Saturday, February 27, 2016

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..

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(){ 
 Serial.begin(9600);
}

void loop(){
 lastTime=millis();
 SensorVoltage = getSensorVoltageInput();
 SensorVRMS = (SensorVoltage/2.0) *0.707; 
 AmpsRMS = (SensorVRMS * 1000)/mVperAmp;
 Serial.print(AmpsRMS);
 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(millis());
 Serial.print(" : ");
 Serial.println(KWH);
}

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;
 }

No comments:

Post a Comment