Arduino current clamp sensor interfacing

As more devices come on the market for home control projects as well as commercial control designs, there comes a requirment to monitor the power consumption of devices. This project uses a clamp on sensor to detect current flow.

The project requires the EmonLib Library and the sensor can be purchased on AliExpress.

#include "lcd3310_GPIO.h"
#include <math.h>
#include "EmonLib.h"

EnergyMonitor emon1;
String toPrint1, toPrint2;
double Irms, thePower;
char buffer1[30], buffer2[30];

void setup()
 emon1.current(1, 111.1);  //pin for current measurement, calibration value
 pinMode(8, OUTPUT);   //enable UEXT power supply
 digitalWrite(8, LOW);
 LCDInit();   //initialize LCD display
 LCDContrast (0xFF);

void loop()
 Irms = emon1.calcIrms(1480); // measure current
 thePower = Irms*230.0;   // we assume voltage is 230VAC if you add transformer to connect to other input you can measure real voltage too

 toPrint1 = "Power:" + String((int)thePower) + "." + String(((unsigned int)(thePower*100))%100) + " ";
 toPrint2 = "Current:" + String((int)Irms) + "." + String(((unsigned int)(Irms*100))%100) + " ";
 toPrint1.toCharArray(buffer1, 30);
 toPrint2.toCharArray(buffer2, 30);
 LCDStr(0, (unsigned char *) buffer1, 0);
 LCDStr(2, (unsigned char *) buffer2, 0);
 LCDUpdate();   // print power and current

The current sensor is a “clamp” type so no direct connection is required, it can be purchased from a number of sites, here is one I found on AliExpress:

The code is sensitive to ADC noise, so small readings will show as current flowing when there is none, in this case, you could code the app to ignore readings below the typical usage of the device. Experimenting with shielding the sensor cable might pay dividends. Ensure there is 1 common earth point for all sensor shields for best results but this may change depending on the electrical layout and proximity of noise sources.

Interfacing to the Arduino:

This code is featured on many web sites.