#include <WiFi.h>
#include <ThingSpeak.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
WiFiClient client;
// Replace with your ThingSpeak details
unsigned long channelID = 3433689;
const char* writeAPIKey = "E0KQNIYKTS91SV4G";
// Analog sensor pin
const int sensorPin = 0; // ESP0 (GPIO0)
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected");
ThingSpeak.begin(client);
}
void loop() {
// Read analog value
int adcValue = analogRead(sensorPin);
// Convert to voltage
float voltage = adcValue * (3.3 / 4095.0);
// LM35 formula: 10 mV = 1°C
// (For Wokwi Analog NTC this is only an approximation.)
float temperature = voltage * 100.0;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
ThingSpeak.setField(1, temperature);
int status = ThingSpeak.writeFields(channelID, writeAPIKey);
if (status == 200) {
Serial.println("Data uploaded successfully");
} else {
Serial.print("Upload failed. Error: ");
Serial.println(status);
}
delay(15000); // ThingSpeak requires at least 15 seconds between updates
}