Hi Patrik,
i use two of these to monitor my washer and dryer. Here is the schematic:
And the MS-Sketch:
/**
SCT_Dual_Sensor MySensors 2.0 EmonLib
*/
// Enable debug prints
//#define MY_DEBUG
// Set Static NodeID
#define MY_NODE_ID 5
// Enable and select radio type attached
#define MY_RADIO_RFM69
#define MY_RFM69_FREQUENCY RF69_868MHZ
#define MY_RFM69_NETWORKID 121
#define MY_RFM69_ENABLE_ENCRYPTION
// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE
#include <SPI.h>
#include <MySensors.h>
#include <EmonLib.h>
#define ANALOG_INPUT_SENSOR1 1
#define ANALOG_INPUT_SENSOR2 2
#define CHILD_ID_PWR1 1 // Id of the sensor child
#define CHILD_ID_PWR2 2 // Id of the sensor child
#define CHILD_ID_RSSI 7 // Id for RSSI Value
//Init Emon
EnergyMonitor emon1;
EnergyMonitor emon2;
//Set Vars
unsigned long SLEEP_TIME = 60000 - 3735; // sleep for 60 seconds (-4 seconds to calculate values)
long wattsum1 = 0;
double kwh1 = 0;
double wh1= 0;
int minutes1 = 61;
long wattsum2 = 0;
double kwh2 = 0;
double wh2 = 0;
int minutes2 = 61;
//Int Messages
MyMessage wattMsg1(CHILD_ID_PWR1,V_WATT);
MyMessage kwhMsg1(CHILD_ID_PWR1,V_KWH);
MyMessage wattMsg2(CHILD_ID_PWR2,V_WATT);
MyMessage kwhMsg2(CHILD_ID_PWR2,V_KWH);
MyMessage rssiMsg(CHILD_ID_RSSI,V_TEXT);
void setup()
{
emon1.current(ANALOG_INPUT_SENSOR1, 30); // Current: input pin, calibration. stock = 30
emon2.current(ANALOG_INPUT_SENSOR2, 30); // Current: input pin, calibration. stock = 30
double Irms1 = emon1.calcIrms(1480); // initial boot to charge up capacitor (no reading is taken) - testing
double Irms2 = emon2.calcIrms(1480); // initial boot to charge up capacitor (no reading is taken) - testing
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Energy Meter Dual SCT013", "0.1");
// Register this device as power sensor
present(CHILD_ID_PWR1, S_POWER);
present(CHILD_ID_PWR2, S_POWER);
present(CHILD_ID_RSSI, S_INFO);
}
void loop()
{
// power used each minute
if (minutes1 < 60) {
double Irms1 = emon1.calcIrms(1480); // Calculate Irms only
if (Irms1 < 0.3) Irms1 = 0;
long watt1 = Irms1*230.0; // default was 230 but our local voltage is about 240
wattsum1 = wattsum1+watt1;
minutes1++;
send(wattMsg1.set(watt1)); // Send watt value to gw
Serial.print(watt1); // Apparent power
Serial.print("W, I= ");
Serial.print(Irms1); // Irms
int var1 = _radio.RSSI;
send(rssiMsg.set(var1)); // Send RSSI value to gw
}
// end power used each minute
if (minutes2 < 60) {
double Irms2 = emon2.calcIrms(1480); // Calculate Irms only
if (Irms2 < 0.3) Irms2 = 0;
long watt2 = Irms2*230.0; // default was 230 but our local voltage is about 240
wattsum2 = wattsum2+watt2;
minutes2++;
send(wattMsg2.set(watt2)); // Send watt value to gw
Serial.print(watt2); // Apparent power
Serial.print("W, I= ");
Serial.print(Irms2); // Irms
}
// end power used each minute
// hours KW reading
if (minutes1 >= 60) {
wh1 = wh1 + wattsum1/60;
kwh1 = wh1/1000;
send(kwhMsg1.set(kwh1, 4)); // Send kwh value to gw
wattsum1 = 0;
minutes1 = 0;
// end of hourly KW reading
}
// hours KW reading
if (minutes2 >= 60) {
wh2 = wh2 + wattsum2/60;
kwh2 = wh2/1000;
send(kwhMsg2.set(kwh2, 4)); // Send kwh value to gw
wattsum2 = 0;
minutes2 = 0;
// end of hourly KW reading
}
//sleep until the next minute
sleep(SLEEP_TIME);
}
Also check this site : https://openenergymonitor.org/emon/buildingblocks/ct-sensors-interface