I am trying to use ESP32 and current sensor SCT-013-020 to post Current data (Irms) to ThingSpeak.
To problem is the following:
When i run the sample program for reading Current data it works fine:
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
#include <WiFi.h>
const char* ssid = "********"; // your network SSID (name)
const char* password = "**********"; // your network password
void setup()
{
Serial.begin(9600);
emon1.current(34, 9); // Current: input pin=34, calibration.
}
void loop()
{
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Serial.print("Power= ");
Serial.print(Irms*230.0); // Apparent power
Serial.print(" ");
Serial.print("Irms= ");
Serial.println(Irms); // Irms= Root mean square current
}
But, when i connect to my wifi network to be able to send data to ThingSpeak the sensor gives me wrong data !!!
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
#include <WiFi.h>
const char* ssid = "*******"; // your network SSID (name)
const char* password = "*******"; // your network password
void setup()
{
Serial.begin(9600);
emon1.current(34, 9); // Current: input pin=34, calibration.
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Serial.print("Irms= ");
Serial.println(Irms); // Irms= Root mean square current
}
Without connecting to WiFi and when the test device is OFF i get 0.2 Ampere (good value)
When i connect to WiFi i get 5 Ampere although the test device is OFF !!!
What is wrong with that ?
Thank you in advance for your time.