Hello everyone, hope everyone is doing well, I am currently doing a project on energy monitoring and I want to connect the data to Blynk app. However, I am getting a reading of 1-1.2A for my IRMS when the sensor is connected or not. When i clamp the SCT013 onto a wire, it reads around 1-1.2A as well. This is my code below, I am hoping someone can help me on this. Thank you all so much. (I got this code from other people on the net)
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_PRINT Serial
#include <driver/adc.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "EmonLib.h"
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
EnergyMonitor emon1;
float kWh = 0;
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
BLYNK_CONNECTED()
void myTimerEvent()
{
Blynk.virtualWrite(V2, millis() / 1000);
}
void setup()
{
adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_DB_0); //This line is to set atten = 0
Serial.begin(115200);
emon1.current(34, 20); // Current: input pin, calibration.
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, myTimerEvent);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
Serial.begin(115200); //wifi
WiFi.begin(ssid, pass); //wifi
while (WiFi.status() != WL_CONNECTED) { //wifi
delay(500);
Serial.println("Connecting to WiFi.."); //wifi
}
Serial.println("Connected to the WiFi network"); //wifi
}
void loop()
{
int val;
val = analogRead(34);
Serial.println(val);
unsigned long previousMillis = millis();
int count = 0;
double Irms = 0;
while ((millis() - previousMillis) < 1000)
{
Irms += emon1.calcIrms(1480); // Calculate Irms only
count++;
}
Irms = emon1.calcIrms(1480);
Irms = Irms/count;
Serial.print(Irms * 230.0); // Apparent power
Serial.print(" ");
Serial.print("W ");
Serial.print(Irms);
Serial.print(" ");
Serial.print("A ");
Blynk.virtualWrite(V5, Irms);
Blynk.virtualWrite(V4, Irms*230);
Blynk.run();
timer.run();
}
Edit - Formatted text. Moderator - BT