ACS712 is a hall effect-based linear current sensor that can measure both AC and DC current. Let’s look at the connection and steps to interface.

For a unipolar supply voltage, it nominally remains at VCC⁄ 2. Thus, VCC = 5 V translates into V IOUT(Q) = 2.5 V. So for 0A the reference voltage is VADC = 2.5V and ADC Value is 512.

Current sensing value is
Vout = (VCC/2) + Sensitivity*Current , Here VCC = 5V
Here, ADC Value = Vout * (1024/5)
= ((VCC/2) + Sensitivity*Current)* (1024/5) = ((5/2) + Sensitivity*I)* (1024/5)
= 512 + (Sensitivity*I*1024)/5
Current I = (5/(1024* Sensitivity))*(ADC Value-512)
For ACS712ELCTR-20AT the sensitivity is 0.1 and the current value is Current I = (5/102.4)*(ADC Value – 512)

float current(uint8_t phase,uint8_t channel)
{
float current;
uint16_t ADC_Value;
ADC_Value=read_adc(channel);
if(phase==AC_Current)
{
if(ADC_Value>=512)
{
current=(ADC_Value-512)*(5/(ADC_Scale*sinsitivity)); //VCC=5V
}
}
else if(phase==DC_Current)
{
current=(ADC_Value-512)*(5/(ADC_Scale*sinsitivity)); //VCC=5V
}
return current;
}
Here for ACS712-05BT sensitivity 0.185, ACS712-20AT sensitivity 0.1 and ACS712-30AT sensitivity 0.066.
Set timer0 overflow vect and at every interrupt service routine read the current. Let’s look at the main program-
#include<avr/io.h>
#include<stdio.h>
#include<avr/interrupt.h>
#include"adc.h"
#include"lcd.h"
float VA=1,Amp_ac,Amp_dc,volage=220;
char str[20];
int main(void)
{
LCD_INIT();
adc_init();
LCD_Clear();
timer_ISR();
while(1)
{
sprintf(str,"AC Current=%.2fA",Amp_ac);
LCD_write_string(1,1,str);
sprintf(str,"DC Current=%.2fA",Amp_dc);
LCD_write_string(1,2,str);
_delay_ms(1000);
}
return 0;
}
ISR(TIMER0_OVF_vect)
{
Amp_ac=current(1,0); //AC Current(1) with channel 0
Amp_dc=current(2,1); //DC Current(2) with channel 1
}
Since we have a PDB supply is fixed at 220V, we can calculate the power = VIcosՓ. If power factor cosՓ=0.98 and V=220V then we can calculate the power from the equation.








Visit Today : 41
Total Visit : 28456