Hello, I am trying to integrate the SCT-013 sensor as Blynk, however I am only getting values equal to 0.
When I use Sketch without blynk the sensor returns the correct values. When I write Blynk lines the sensor values are always equal to 0.
I am using ESP32 card.
Can someone help me find the problem? Thank you.
//Carrega as bibliotecas
#include "EmonLib.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp32.h> // Blynk-ESP32
#include <WiFi.h> // Wi-Fi
#include <WiFiClient.h> // Wi-Fi client
BlynkTimer timer;
//-------- Token de Autenticação -----------
char auth[] = "XXXXX";
//-------- Configurações de Wi-fi -----------
const char* ssid = "XXXXX";
const char* password = "XXXXX";
int lcdColumns = 16;
int lcdRows = 2;
long Cont;
LiquidCrystal_I2C lcd(0x3F, lcdColumns, lcdRows);
EnergyMonitor emon1;
EnergyMonitor emon2;
#define VOLT_CAL 127
//Pino do sensor SCT
#define ADC_INPUTV 15
#define ADC_INPUTC 2
void sendSensor()
{
emon2.calcVI(20, 1000);
float supplyVoltage = emon2.Vrms;
if (supplyVoltage <= 50) {
supplyVoltage = 0;
}
float Irms = emon1.calcIrms(1480);
if (Irms <= 0.19) {
Irms = 0;
}
float Pot = (supplyVoltage * Irms);
if (Cont <= 2) {
lcd.setCursor(4, 0);
lcd.print("Test");
lcd.setCursor(7, 1);
lcd.print("EMS");
if (Cont == 2) {
lcd.clear();
}
}
if (Cont > 2) {
Blynk.virtualWrite(V1, supplyVoltage);
Blynk.virtualWrite(V2, Irms);
Blynk.virtualWrite(V3, Pot);
lcd.setCursor(0, 0);
lcd.print("V:");
lcd.setCursor(2, 0);
lcd.print(supplyVoltage, 0);
lcd.setCursor(5, 0);
lcd.print("Vac");
Serial.print("Tensão: ");
Serial.println(supplyVoltage);
lcd.setCursor(9, 0);
lcd.print("I:");
lcd.setCursor(11, 0);
lcd.print(Irms, 1);
lcd.setCursor(14, 0);
lcd.print("A");
Serial.print("Corrente: ");
Serial.println(Irms);
lcd.setCursor(0, 1);
lcd.print("Potencia:");
lcd.setCursor(9, 1);
lcd.print(Pot);
lcd.setCursor(15, 1);
lcd.print("W");
Serial.print("Potencia: ");
Serial.println(Pot);
}
Serial.print("Contador:");
Serial.println(Cont);
Cont++;
delay(100);
}
void setup()
{
Serial.begin(115200);
lcd.init();
lcd.backlight();
Blynk.begin(auth, ssid, password);
emon2.voltage(ADC_INPUTV, VOLT_CAL, 1.7); //PASSA PARA A FUNÇÃO OS PARÂMETROS (PINO ANALÓGIO / VALOR DE CALIBRAÇÃO / MUDANÇA DE FASE)
emon1.current(ADC_INPUTC, 7.5); // Initialize emon library (30 = calibration number)
timer.setInterval(2000L, sendSensor);
}
void loop()
{
timer.run();
Blynk.run();
}