#include <WiFi.h>
#include "ThingSpeak.h"
#define POT_PIN 34 // Potentiometer pin
const char* ssid = "Wokwi-GUEST";
const char* password = "";
unsigned long channelID = 3244361; // Replace with your Channel ID
const char* writeAPIKey = "BG3JHSBQ7QF3G9AM";
WiFiClient client;
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected");
ThingSpeak.begin(client);
}
void loop() {
int adcValue = analogRead(POT_PIN);
float voltage = 230.0; // Fixed voltage
float current = (adcValue / 4095.0) * 10; // Simulated current (0–10A)
float power = voltage * current;
Serial.println("Smart Energy Meter");
Serial.print("Voltage: "); Serial.println(voltage);
Serial.print("Current: "); Serial.println(current);
Serial.print("Power: "); Serial.println(power);
ThingSpeak.setField(1, voltage);
ThingSpeak.setField(2, current);
ThingSpeak.setField(3, power);
ThingSpeak.writeFields(channelID, writeAPIKey);
delay(15000); // ThingSpeak update delay
}