ACS712(Current Sensor) Arduino Tutorial.

 ACS712(Current Sensor) Arduino Tutorial.

How to Measure AC Current with an Arduino and an ASC712

ACS 712 on IC StationThe cool thing about an ACS712 is that current is measured in two directions.  What this means is that if we sample fast enough and long enough,  we sure to find the peak in one direction and the peak in another direction.With both peaks known, it is a matter of knowing the shape of the waveform to calculate the current.   In the case of line or mains power, we know that waveform to be a SINE wave.   Knowing that allows us to apply a basic electronic formula.





In most cases, an expression of AC current  will be in a value known as RMS.   In order to use the ACS712 current sensor to measure AC current, it is important to understand how to calculate an RMS current value from the device readings.
The formula that is applied here is very basic and is right out of any basic electricity or electronics manual.
VPP VPEAK RMS
Conversion for a sine wave with a zero volt offset (like your mains or line power) is performed as follows…

Step 1:- Find the peak to peak voltage
Step 2:- Divide the peak to peak voltage by two to get peak voltage 
Step 3:- Multiply the peak voltage by 0.707 to yield rms volts 

Once RMS voltage is Calculated, it  is simply a matter of multiplying by the scale factor of the particular ACS712 to yield the RMS value of the current being measured.

Arduino ACS712 AC Measurement Tutorial Setup

Fundamental to performing this tutorial safely is knowing what the current rating of your ACS712 and the amount of current that your load requires.
Connect the components as shown below: ACS712 Arduino AC CurrentAlso take a look at how I make a call to the ‘VPP‘ function from the main loop.  In that function, I take interupted AC samples for one second while recording the maximum and minimum values.  From this I will calculate the peak to peak voltage measured.

Code:-

const int sensorIn = A0;
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module


double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;



void setup(){ 
 Serial.begin(9600);
}

void loop(){
 
 
 Voltage = VPP();
 VRMS = (Voltage/2.0) *0.707; 
 AmpsRMS = (VRMS * 1000)/mVperAmp;
 Serial.print(AmpsRMS);
 Serial.println(" Amps RMS");

}

float VPP()
{
  float result;
  
  int readValue;             //value read from the sensor
  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;
 }

Comments