With this project you can monitor the energy comsuption of you house for an example, you can also estimate how much you will pay in the end of the month and check the actual the value before the due date.
I have two YHDC STC-013-100A Sensors:
And thanks to the ESP-8266 wifi module, I can send the result data to Cayenne and check everywhere I want, the most interesting is that I have configured an automatic event trigger every month which will Reset to zero the KW/h so the bill is closed, a new measurement starts.
Code:
#include "CayenneESP8266Shield.h"
#include "EmonLib.h"
#define EspSerial Serial
ESP8266 wifi(EspSerial);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "XXXX";
// Your network name and password.
char ssid[] = "XXXX";
char password[] = "XXXX";
#define VIRTUAL_PIN0 V0
#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V3
#define VIRTUAL_PIN3 V4
#define VIRTUAL_PIN3 V5
EnergyMonitor emon1, emon2;
unsigned long ltmillis, tmillis, timems, previousMillis;
int rede = 127.0, ResetState = 0;
double kwhTotal, kwhTotal_Acc, vlreais, vlreais_Acc;
void setup()
{
pinMode(13, INPUT); //Reset Energy Bill every month for a new measurement - Automatically Triggered by Cayenne
EspSerial.begin(115200);
delay(10);
Cayenne.begin(token, wifi, ssid, password);
}
void loop()
{
emon1.current(A0, 60); //Current sensor for phase A at pin A0 (value 60 for 33R resistor)
emon2.current(A1, 60); //Current sensor for phase B at pin A1 (value 60 for 33R resistor)
previousMillis = millis();
Cayenne.run();
}
CAYENNE_OUT(VIRTUAL_PIN0)
{
ResetState = digitalRead(13); //Reset Energy Bill every month for a new measurement - Automatically Triggered by Cayenne
if (ResetState == 0)
{
ltmillis = tmillis;
tmillis = millis();
timems = tmillis - ltmillis;
double Irms1 = emon1.calcIrms(1480); // Calculate Irms from Phase A
double Irms2 = emon2.calcIrms(1480); // Calculate Irms from Phase B
double IrmsT = Irms1+Irms2; // Sum both phases
kwhTotal = (((IrmsT*127.0)/1000.0) * 1.0/3600.0 * (timems/1000.0)); //Calculate KW/h
kwhTotal_Acc = kwhTotal_Acc + kwhTotal;
vlreais = kwhTotal * 0.55; //Calculate estimated price (55 cents in this case for each KW/h)
vlreais_Acc = vlreais_Acc + vlreais;
Cayenne.virtualWrite(V0, kwhTotal_Acc); //Send result data to Cayenne
Cayenne.virtualWrite(V1, vlreais_Acc);
Cayenne.virtualWrite(V2, kwhTotal);
Cayenne.virtualWrite(V3, vlreais);
Cayenne.virtualWrite(V4, Irms1);
Cayenne.virtualWrite(V5, Irms2);
}
else{ //If Reset pin is on, reset all counters to zero (new month).
kwhTotal = 0;
kwhTotal_Acc = 0;
vlreais = 0;
vlreais_Acc = 0;
Cayenne.virtualWrite(V0, kwhTotal_Acc);
Cayenne.virtualWrite(V1, vlreais_Acc);
Cayenne.virtualWrite(V2, kwhTotal);
Cayenne.virtualWrite(V3, vlreais);
}
}
Comments