Pages: [1]   Go Down
Author Topic: how to use ACS712 with Arduino ?  (Read 3296 times)
0 Members and 1 Guest are viewing this topic.
Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi friends,

Im making a current measuring device with ACS712 and ARDUINO 328P IC.

I made a circuit, but I have some problems in reading the ACS712 hall effect sensor input. ( it produces an analog input )

Below is the code I used. ( i got it from internet )

Quote
void setup() {
 
  Serial.begin(9600);
}
 
void loop() {
 
  float average = 0;
  for(int i = 0; i < 10; i++) {
    average = average + (.0264 * analogRead(A3) -13.51) / 1000;
    delay(100);
  }
  Serial.println(average); 
}


Below is the result I got . It is not stable .

Quote
-0.00
-0.00
-0.00
-0.00
-0.00
-0.00
-0.00
0.00
0.00
0.00
0.00
0.00
0.00  // now, here I connected a load ( a 1000W water heater )
-0.01
-0.03
-0.03
-0.02
-0.02
-0.01
-0.01
-0.01
-0.01
-0.00
-0.00
-0.01
-0.01
-0.02
-0.03

Any help please ?
Logged

Dileesha Amarasena

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your calculation is a little confusing.
Could you add '(' and ')' around the multiplication, so it is clear that the multiplication is done first.

To solve your problem, go back one step.
Show the value of analogRead() on the serial monitor without the average.

I assume the heater is powered by the mains ? 110 or 240V AC ?
If so, you will read AC values, changing at 50Hz or 60Hz.
The average of a AC value will be zero.

You have to know what the numbers ".0264" and "-13.51" do, and explain that in the sketch. You can't write a good sketch if you don't know what those numbers are.
By the way, I have no idea what those numbers are, I would calculate the voltage of the analog input and use the sensitivity of the sensor in the sketch to calculate the current.
« Last Edit: May 26, 2013, 08:31:19 am by Erdin » Logged

Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Erdin

Yes it's a 230V 50Hz mains line.

But I'm not really sure of what that -13.51 means, because I just got this from internet and just used.

Ok Erdin, just forget that -13.51. Just please tell me the way you follow if you want to measure the AC voltage using this sensor connected to arduino ?

The sensor(ACS712) is for -20 to 20A AC/DC measuring . And it shows 2.5V with no current flowing through the IC.

Thanks,
Dileesha.
Logged

Dileesha Amarasena

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The output is somewhere in the middle.
So 2.5V with no current is good.

To measure the current with the 50Hz or 60Hz mains requires a lot of programming if you want to do it right.
Take a look at this: http://openenergymonitor.org/emon/
You should find explanation about current measurement.

For a rough indication, you could find the minimum (negative current) and the maximum (positive current) during an interval (for example 100ms). They should be almost equeal to each other with an AC current and you could use that to calculate for example the rms value.
https://en.wikipedia.org/wiki/Alternating_current


If you want to know an AC current, you have to do a number of samples and you need some calculation.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11730
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But I'm not really sure of what that -13.51 means, because I just got this from internet and just used.

Its -0.0264 x 512

That line:
Code:
    average = average + (.0264 * analogRead(A3) -13.51) / 1000;
would be much clearer as
Code:
    sum += 0.0264 * (analogRead(A3) - 512) ;
and take mean after the loop by dividing by the loop count.

But of course averaging an AC waveform is pointless - you want the rms value, hence something like:

Code:

  float sum = 0;
  for (int i = 0; i < N; i++) {
    float current = 0.0264 * (analogRead(A3) - 512) ;  // in amps I presume
    sum += current * current ;  // sum squares
    // no delay, make sure N large enough to cover many waveforms.
  }
  float average = sqrt (sum / N) ;  // root-mean of squares
Logged

[ I won't respond to messages, use the forum please ]

Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks markt,

I will try.
« Last Edit: May 28, 2013, 11:00:14 am by Dileesha » Logged

Dileesha Amarasena

Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Erdin

Thanks for the info.


Logged

Dileesha Amarasena

Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok well I then tried with emonLib from openenergymonitor.

Please note : I have connected this to 230V AC 50Hz domestic single phase mains line.

And now i get some outputs on my serial monitor. ( with no load connected )

Quote
DAY TIME                Vrms    Irms   PF      Apparent Pwer   Real Power
2013/5/28 18:0:11   245.2   0.3   -0.05   64.83                  -3.04   
2013/5/28 18:0:12   239.9   0.2   -0.03   66.89                  -2.18   
2013/5/28 18:0:17   239.7   0.3   -0.04   66.28                  -2.97   
2013/5/28 18:0:18   240.6   0.3   -0.12   62.00                  -7.19   
2013/5/28 18:0:19   240.0   0.2   -0.07   60.95                  -4.29   
2013/5/28 18:0:23   240.6   0.2   -0.02   59.23                  -1.27   
2013/5/28 18:0:23   239.0   0.3   -0.02   71.22                  -1.15   
2013/5/28 18:0:24   240.7   0.2   -0.01   71.94                  -0.47   
2013/5/28 18:0:29   240.1   0.3   -0.07   62.82                  -4.56   
2013/5/28 18:0:29   239.9   0.3   -0.03   63.40                  -1.92   
2013/5/28 18:0:30   239.5   0.3   -0.03   69.33                  -1.76   
2013/5/28 18:0:34   239.7   0.3   -0.04   67.83                  -2.46   
 

Within the main code, there is a calibration ( we can set anything we want as that constant ) value to be put. Also they ask us to put the phase difference . So i'm confused because I don't really know which value I should put as PHASE DIFFERENCE ?

Further I hope to use this system for resistive loads such as water heaters and also for inductive loads such as motors.

Thanks,
Dileesha
Logged

Dileesha Amarasena

Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

below is a part of the code which includes that values

Quote
void setup()

  Serial.begin(9600);
  lcd.begin(16, 2);
 
  emon1.voltage(2, 468.26, 0);  // Voltage: input pin, calibration, phase_shift
  emon1.current(3, 7.4);       // Current: input pin, calibration.[/quote]
Logged

Dileesha Amarasena

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11730
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you read the comments in the eMon library - that ought to explain the calibration values (if not
then that's a bit poor).
Logged

[ I won't respond to messages, use the forum please ]

Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

I read in an article that,

when a purely resistive load is connected, then the true power(P) = I2 * R
and the apparent power is same ( since App.Pwr = I2*Z )

when a purely reactive load is connected, then the true power (P) becomes ZERO (0) .

link : http://www.allaboutcircuits.com/vol_2/chpt_11/2.html

My problem is, now the above published serial monitor output results have been obtained with NO LOAD connected . But still how it gives a value for apparent power ?

And can real power and power factor be NEGATIVE ?



I also tested connecting a purely resistive WATER HEATER as a load. But still the real power remains below 1, but apparent power goes high up to like 900. Im confused ?

Please help.


Thanks,
Dileesha.
Logged

Dileesha Amarasena

Colombo
Offline Offline
Newbie
*
Karma: 1
Posts: 36
Bachelor in EEE Student
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@MarkT

Yes I did . Even I have gone through their website many times . But they haven't explained how to select a value for phase shift. But in their default example they have put the phase shift as 1.7 . And the Voltage Calibration as 234.6 . It somehow works, but not accurate. That's why I thought of changing the phase shift value.

May be its not needed to change the phase shift value. But I'm searching for a way to make this reading accurate.

Logged

Dileesha Amarasena

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11730
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think phase shift compensates for the shift in the voltage transformer used to sense mains voltage.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: