Calculate Energy Usage using Current Sensor ACS712 30A

This is a simply cheap solution to calculate Energy consumed by your gears..But still the accuracy i have not tested..Buy a
module as shown below with ACS712 and please make sure of the current rating according to your requirement.

             The module has one Vcc, one Gnd and one Vout pins so simply you connect the Vout pin to any Analog input of Arduino and power up the module from Arduino. But don’t forget to change the analog pin no in the provided sketch..
Measuring KWh Current Using ACS712
const int sensorIn = A3;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
double SensorVoltage = 0;
double SensorVRMS = 0;
double AmpsRMS = 0;
float KWH=0;
uint32_t lastTime=0;

void setup(){ 

void loop(){
SensorVoltage = getSensorVoltageInput();
SensorVRMS = (SensorVoltage/2.0) *0.707; 
AmpsRMS = (SensorVRMS * 1000)/mVperAmp;
Serial.print("RMS Current ");
Serial.print("Energy ");
KWH=KWH+(((AmpsRMS*220*0.9)/3600)*(millis()-lastTime)); // Taken 220V RMS (Indian Scenario) and PF 0.9
Serial.print(" : ");

float getSensorVoltageInput()
float result;

int readValue; 
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here

uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1 Sec
readValue = analogRead(sensorIn);
// see if you have a new maxValue
if (readValue > maxValue) 
/*record the maximum sensor value*/
maxValue = readValue;
if (readValue < minValue) 
/*record the maximum sensor value*/
minValue = readValue;

// Subtract min from max
result = ((maxValue - minValue) * 5.0)/1024.0;

return result;


Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WGLabz
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Related posts