Wrong AC Current reading

Hello guys! I'm using two analog inputs voltage & current with serial communication from arduino to labview. I use ACS712 for the current sensor. The readings I get are ranging from -6 to +5 from the AC signal after the calculations. If I take the RMS, I will get around 3.9 - 4.0. I use 230AC supply with load 229ohms so I should get around 1.004? The value I get should be near to 1 but I'm getting 3.9 RMS?

I've double checked the hardware(connection) and software(calculations) and I don't think there is anything wrong? What should I do? This value I'm getting is totally far from 1A that I should be getting!

I'm taking the reading from Analog input 0 to divide 1023 then * 5000. Then I minus the 2500 offset and divide 185.


Here is my code:


const int analogIn0 = A0;
const int analogIn1 = A1;
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
int RawCurrentValue= 0;
int RawVoltageValue= 0;
int ACSoffset = 2500;

int Denominator = 0;
float AcVoltage = 0;
float Voltage0 = 0;
float Voltage1 = 0;
float Amps = 0;

void setup(){ 

void loop(){
 RawCurrentValue = analogRead(analogIn0);
 RawVoltageValue = analogRead(analogIn1);

 Denominator = 10000/130000;
 Voltage0 = (RawCurrentValue / 1023.0) * 5000; 
 Voltage1 = (RawVoltageValue / 1023.0) * 5000; 
 AcVoltage = (Voltage1 / Denominator ) ;
 Amps = ((Voltage0 - ACSoffset) / mVperAmp);
Serial.print(", ");



I've also serial printed the 3 values, the RawCurrentValue, the Millivolt and the Current reading. I verified that the Millivolt values are correct, so I assume the rawcurrentvalue shouldn't be the problem though.. I should be getting a current close to 1.

The values of the RawCurrentValue is ranging from 290-705. Millivolt is ranging from 1400-3450 and current is from -5.96 to 5.16. These are the values if I use 230AC with load 229 ohms.

Really appreciate if you guys can help!

Robert Wall's picture

Re: Wrong AC Current reading

That device is ratiometric, therefore the output depends directly on its supply voltage. Can we have a circuit diagram?

How are you calculating the rms value?

You've quoted so many numbers that it's difficult to follow what you're trying to do. OK, you want to measure voltage and current, but in detail I can't follow you. All I think your sketch is doing is printing sampled voltages/currents from random points on the alternating wave.

Here's what I know and what I'd do:
Any d.c. offset will spoil the readings, therefore subtracting half-scale isn't the best way to remove it, because the offset might not be exactly half-scale. In emonLib we use a low pass filter to extract the true offset, then we can subtract the true value. What you're left with is a series of values that represent samples at a sequence of points on the wave. To get the rms value, you need to square each, then take the average over a whole number of mains cycles (or a sufficient number of cycles so that the error from a part-cycle doesn't matter too much), then get the square root. Finally, you need to calibrate the result.

Given that, I'd simply plug your sensor pin numbers into emonLib, which does all that maths for you, then I'd sit down and work through the Building Blocks article on calibration theory - don't expect to understand it the first time round, you'll need pencil, paper and a calculator and work through it several times to understand how it all works - and calculate your calibration constant. It will depend of the sensitivity of your ACS712, which you know from the data sheet and its supply voltage, and the ADC reference voltage of your Arduino.
To give you a guide, a standard shop CT with the standard burden resistor gives about 1.1 V rms at 100 A, and the current calibration constant is 90.9, so (very, very roughly) it's the number of amps to get 1 V at your ADC input. Likewise for voltage the AC adapter and voltage divider steps the mains voltage down to about 1.1 V so the voltage calibration constant is (again very, very roughly) the mains voltage for 1 V at the ADC input. (It doesn't matter whether you use rms, peak or peak-peak, as long as both are the same units.)

When you've got past the initial testing, do NOT put print statements inside the sampling loop - they will slow it down to the point where the numbers are almost meaningless. You will need two loops - a 'fast' loop to read the analogue values, square and accumulate, and a 'slow' loop around that to do the average, the square root, the scale factor to calibrate and print the result.
To give you an idea of the speed, emonLib takes roughly 2500 sample pairs (voltage and current) per mains cycle, i.e. about 50 sample pairs per second.

[Edit 2]
In your code, what value does "Denominator" get - bear in mind it's declared as an Integer?

lamela's picture

Re: Wrong AC Current reading

Thanks for your reply!

Is the emonLib compatible with the Arduino Yun? So I just have to change the input pin to A0 & A1 for current and voltage from the sketch. Do you have a list of how the calculations are being made or how do I change the calculations for the current & the voltage? Because I'm using a different load, a current sensor, different transformer  to step down voltage with different resistors for the voltage dividing so I have to change the values a bit.

I'll probably try this tomorrow when I get back to my school's lab! 

Robert Wall's picture

Re: Wrong AC Current reading

"Is the emonLib compatible with the Arduino Yun?"
I don't know the Arduino range, but it is maths so all you will have to do is change some pin references.

"Do you have a list..."
No, that is the point of you studying the explanation of the theory behind the calibration. (And that is why I gave you some very rough values so that you would know when your value was in the right area.)

lamela's picture

Re: Wrong AC Current reading

Ok! The calibration for the voltage part is alright to me but I'm having trouble finding the current calibration. Since I'm following the calculations from here: http://openenergymonitor.org/emon/buildingblocks/ct-and-ac-power-adaptor-installation-and-calibration-theory

I don't know what's the secondary, primary current and transformer ratio for the ACS712 current sensor.. Do you have any idea on how to calculate it? The sensitivity is 0.185V/mA. There is 1.004A flowing through the current sensor and about 2.2V on the analog input. The supply voltage is 5V and based on the datasheet, ACS712 uses 1.2 mΩ burden resistor. 

I'm kind of stuck here. Really appreciate if you could help me with this! 

Robert Wall's picture

Re: Wrong AC Current reading

You will need to treat this as a "voltage output current transformer".

But first, you need to get the correct numbers - the sensitivity is not 0.185V/mA (obviously - if you give it 1 A you cannot have 185 V out. A typo?)

The data sheet says 185 mV/A, so I'll use that.

Look at the section on the page you linked: "If you use a current transformer with a built-in burden (voltage output type)"
Where it says "For example, the Yhdc SCT-013-030 gives 1 V at a rated current of 30 A, so for this transformer you have: current constant = 30 ÷ 1 = 30", that tells you exactly what you want.

So applying the same thinking to yours, yours gives you 185 mV at a current of 1 A, therefore:
your current constant = 1 (A) ÷ 0.185 (V) = 5.405

lamela's picture

Re: Wrong AC Current reading

Thanks for your reply!

Hmm.. If I take 5.405 as the current constant, I get 3.67A rms on the serial monitor? But I'm supposed to get about 1A? Even for the voltage constant, I calculated 233.94 as the Vmain and the counts is 185.75, I take 233.94/185.75 and I got 1.259 as the voltage constant. But if I input this value 1.259 I'm getting 1.07Vrms..

What do you think is the problem here?

here are the readings I got

(realpower, apparent power, Vrms, Irms, power factor)

3.98 3.96 1.07 3.69 1.01 

Please help! The deadline of my project is two more days :(


Edit: I've realized if I divide the Irms by 4, I get the correct reading. This is the same problem when I use the normal calculation to calculate? What am I doing wrong?


Robert Wall's picture

Re: Wrong AC Current reading

Which version of the ACS712 do you have. There are three, with different sensitivities (see Page 5 of the data sheet):

ACS712ELCTR-05B-T which is 185 mV/A
ACS712ELCTR-20A-T which is 100 mV/A
ACS712ELCTR-30A-T which is 66 mV/A

Are you using the latest version of emonLib? The code you included in your first post will not work with alternating current, so you must use emonLib to get the rms values. You want a sketch like http://openenergymonitor.org/emon/buildingblocks/arduino-sketch-current-...

Can you attach your complete sketch?

lamela's picture

Re: Wrong AC Current reading

I'm using the ACS712ELCTR-05B-T which is 185 mV/A. Yeap, I got it from the website not long ago?

Is the sketch correct? Is it the latest?

Robert Wall's picture

Re: Wrong AC Current reading

Obviously something is not what it is supposed to be, but everything looks correct to me.

What is the rms voltage from the ACS712? Measure it with respect to Vcc/2 (2.5 V dc), not with respect to GND in case your meter does not remove the dc component.
Measured on the dc voltage range, the output should be 2.5 V dc, though the filter in emonLib should remove any offset.

"here are the readings I got

(realpower, apparent power, Vrms, Irms, power factor)

3.98 3.96 1.07 3.69 1.01 "

What was the actual current that produced those numbers?

If you connect an unused analogue input to Vcc, and do
do you get 1023 or something very close to that?

I have checked the numbers with an emonTx (with input pins suitably changed), and with 2.4 V on the voltage input ( ÷ 13 = 185 mV ac on the analogue input pin), your sketch gives me 1.04 A rms, so I think the calibration constant is correct.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.