#include #include int mqsensor=A0; #include #include LiquidCrystal_I2C lcd(0x27, 16, 2); // Replace with your WiFi credentials const char* ssid = "FABLAB"; const char* password = "12345678"; // Replace with your ThingSpeak Write API Key const char* apiKey = "58R2B0HEWSSK6WYK"; // ThingSpeak API URL const char* server = "http://api.thingspeak.com/update"; void setup() { Serial.begin(115200); lcd.begin(); lcd.backlight(); WiFi.begin(ssid, password); //Serial.print("Connecting to WiFi..."); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } //Serial.println("\nConnected to WiFi!"); } void loop() { if (WiFi.status() == WL_CONNECTED) { HTTPClient http; int value= analogRead(mqsensor); Serial.print("Sensor value="); Serial.println(value); // Generate random values int value1 = value; // Example: Temperature lcd.setCursor(0, 0); lcd.print("Shivraj"); // Add spaces to clear previous text lcd.setCursor(0, 1); lcd.print("Sensorvalue="); lcd.setCursor(12, 1); lcd.println(value1); // Construct the request URL String url = String(server) + "?api_key=" + apiKey + "&field1=" + String(value1); //Serial.println("Sending data to ThingSpeak..."); // Serial.println(url); // Send data to ThingSpeak http.begin(url); int httpCode = http.GET(); if (httpCode > 0) { // Serial.println("Data sent successfully!"); } else { // Serial.println("Failed to send data."); } http.end(); } else { //Serial.println("WiFi Disconnected!"); } delay(500); // ThingSpeak allows updates every 15 seconds }