Go Down

### Topic: Really need help with acs712 and Arduino (Read 10570 times)previous topic - next topic

#### kb2bsc

##### May 26, 2010, 05:03 pm
Hi everyone,I have an acs712 working with arduino and everything is ok, its sends a 2.5 - 2.7v reading on the analog pin and so on, but i can´t find out how to caculate power (KW or KW//h) can someone help with this problem? I would realy apreciate it if anyone could post the equation if they´d allready done one of these. I´m in Europe so its sensing +/- 230VAC 15A.

Thanks,

Chris

#### Arnonh

#1
##### May 28, 2010, 09:16 pm
this web site has information on the subject i think you can use the acs712 insted of the CT sensor
http://openenergymonitor.org/emon/

#### jeremy_jackson

#2
##### Oct 29, 2010, 05:06 pm
The output from the ACS712 is ratiometric so you will have to come up with y=mx+b values to calculate your current.

For the 5A version, the output runs from 0amps,2.5v to 5amps,3.5v...or 0amps,512 analogcounts to 5amps,716 analog counts.

So.....the equation for the 5a version is y=.0245(analogcounts)-12.55

Here is the calc from my arduino sketch:

#### amitkc

#3
##### Dec 19, 2010, 08:40 am
Hello,
I am using ACS 712 with arduino to measure the current. I tried to do it as per the Sparkfun instructions. (Except I have connected 1 microfarad caps instead of 0.1 microfarad).
I am getting readings from 0 to 1024 on the serial monitor of Arduino IDE. Can anyone tell me how to calibrate the sensor(ACS 712) to get exact current values on serial monitor?

I mean if ACS 712 outputs the analog voltage, then why am I getting digital readings on the serial monitor?

#4
##### Dec 19, 2010, 10:18 amLast Edit: Dec 19, 2010, 10:41 am by graynomad Reason: 1
Quote
I mean if ACS 712 outputs the analog voltage, then why am I getting digital readings on the serial monitor?

Just guessing here, but I'd say it's got something to do with the fact that you're reading the analogue values via an ADC (Analogue to Digital Converter) and sending the digital value to the serial monitor.

Or was that a trick question?

PS, why don't they have a sarcasm smiley?

Sorry amitkc, as for calibrating, assuming the 712 is linear measure the current with a known accurate meter, compare that value against what you are reading from the 712, then multiply by a fudge factor and/or apply an offset to bring the ADC value into line. See Jeremy's post above.

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

#### amitkc

#5
##### Dec 19, 2010, 11:04 pm
well, let's say even if you have a DMM, It measures RMS values and not the average. So, if the values are changing instantaneously. So, it really makes it difficult to measure average value of current.
And basically, the question is how to develope a formula which can convert those voltage readings into current ?

#6
##### Dec 20, 2010, 02:11 am
I gather that the thing you want to measure is constantly fluctuating and therefore you can't get a good reading with the DVM.

You can't calibrate form a moving target, so set up a known stable current with a steady PSU and a resistor. Get the 712 callibrated with that.

Quote
how to develope a formula which can convert those voltage readings into current ?

I think that's what Jeremy's formula does. But maybe you can used the map() function.

Let's say you're getting readings from 200 to 600 and you know these equate to currents in the range 1A to 5A. Then the call

x = map(reading, 200, 600, 1, 5);

should work except that map() deals with ints so the returned values could only 1, 2, 3, 4 or 5 which is a little course. The way around that is to work with mA instead of A

x = map(reading, 200, 600, 1000, 5000);

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

#### amitkc

#7
##### Dec 20, 2010, 02:34 am
I will try the map function. I am assuming that I will have to call that map function in MS excel and not in Arduino IDE.

Also, I tried Jeremy's formula, but it gave me negative readings for those digital numbers. So, I thought I should calibrate for my sensor. (My previous experience with Sharp Long Range IR sensor tells me to do so.)

The digital readings on the serial monitor vary from around 480 to 1023 for motor speed of 50 rpm. I am using Mabuchi FA 130 motor.
If I increase the speed to 100 or 200 still the readings go as high as
1023. This tells me that the readings are varying or overshooting instantaneously because of the PWM technique, since they did not overshoot or fluctauate as much for a speed of 255; which is maximum.

So, in order to define that how much is average current for speed of 50, for speed of 100 and so on, first I will have to convert those digital numbers in voltage with the help of ADC resolution formula i.e.

Once I know that, I will also have to see that for what voltage, what current do I have for what rpm. I think the current might vary according to load condition and rpm , so u can not really say that there is a particular amount of current for corresponding digital number or voltage.

But all this process will not yield an equation between voltage and current which is applicable for all rpm (i.e. duty cycles) from 0 to 255.
The statement I made above has the challenge and question hidden in itself. Let me know if you can help me with that.

Thanks again,

Amit

#8
##### Dec 20, 2010, 09:00 amLast Edit: Dec 20, 2010, 09:01 am by graynomad Reason: 1
Quote
I am assuming that I will have to call that map function in MS excel and not in Arduino IDE.

AFAIK there is no map function in Excel, you'll have to do it in the Arduino.

The approach I suggested above is just for getting the instantaneous current with no thoughts about voltage or power factor etc. I was not aware of the other requirements until your last post. This however has no bearing on calibrating the 712, that can be done with a static setup.

I really don't know anything about power factors, I do know that the voltage being applied to the motor is easy to read, as is the RPM. How you combine that lot to get what you want I'm not sure.

One thing I find a little strange though is

Quote
The digital readings on the serial monitor vary from around 480 to 1023 for motor speed of 50 rpm.

Are you saying that you get this huge variation (in current?) with nothing changing?

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

#### amitkc

#9
##### Dec 20, 2010, 09:39 amLast Edit: Dec 20, 2010, 09:40 am by amitkc Reason: 1
Rob,
sorry for the "map" thing. I was not familiar with the function, so I just guessed since u did not mention the environment. Thank you for that .
Now, let me tell you what exactly I am trying to acheive.

I am trying to measure the current withdrawal from my battery. Its (9.6v, NiCd,700mAh).

At very first, I connected ACS 712 in series with just one motor .(since this is the major load in my rover. Motors are connected to Adafruit motorshield.) I was getting fluctuation in the DMM and ACS readings as well.

So, further I connected ACS 712 in series with battery and that  in series with DMM,with that, the DMM readings are not fluctuating, but ACS readings are still fluctuating. I am sure this is because of the PWM technique Arduino uses. Now, one more thing here is, if I increase the Vref to 5v by rotating the Vref pot on ACS 712 at its max position and making the gain maximum, I constantly get the value 1023. No fluctuation. (which really does not make sense.) If I set this pot to min
the values are again constantly zeroes.(catches my nerves..!!!)

Further, I just tried to play with the sensor and kinda tuned the both pots just to get some sensible values on serial monitor. I got the values mentioned here for the constant current of 0.48A (current measured on DMM)

For 50 rpm,
0

0

121

219

189

204

220

0

0

141

198

216

191

193

0

0

Now, If I am correct, these values are representing the voltage and not the current since, the output of the ACS712 is analog voltage. I also know the current (bcoz of the DMM), but I do not know the voltage values, as I have tuned the pot (Vref and Gain) at some random position and now, I am not able to understand what is Gain value and what is Vref value!!! having said that , how do I calculate the voltage values from the digital numbers I am getting ?

If you think there is something wrong my set up or strategy to measure the current or if some of my concept is wrong let me know.

Hey, by the way, where did u get the power factor thing into this
..I am running a DC system.

Thanks again,
Amit

#10
##### Dec 20, 2010, 11:18 amLast Edit: Dec 20, 2010, 11:21 am by graynomad Reason: 1
Quote
where did u get the power factor thing into this

No idea, senior moment maybe

Quote
if I increase the Vref to 5v by rotating the Vref pot on ACS 712 at its max position and making the gain maximum, I constantly get the value 1023. No fluctuation. (which really does not make sense.) If I set this pot to min
the values are again constantly zeroes.(catches my nerves..!!!)

Don't know without seeing the circuit, but it looks like it's being over driven and maxing out.

But let me get this right, you have

motor---712---DMM---PWM

Is that correct?

If so I think there's no way you'll get a good reading because of the PWM. The PWM will produce X amps or 0 amps, there are no values in between, it's the ratio between the two that counts. If you're reading the current as above you'll get X for some readings and 0 for others. Exactly how that pans out will depend on the sampling frequency but I imagine it would look very much like you are describing as the two frequencies (PWM and your sampling) beat.

It's possible that the DMM gets a different and stable reading because it samples in a different manner, maybe true RMS or something.

You say the DMM shows .48A, is this what the motor is spec'd at, my guess is that the specs say quite a lot more.

Anyway as I said I think there's no way to get a good reading if the setup is as I have drawn above, and if it is it's not immediately clear to me how one would get a proper reading.

Quote
Now, If I am correct, these values are representing the voltage and not the current since, the output of the ACS712 is analog voltage.

The readings are voltage, but proportional to the current, so affectively they are current values.

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

#### amitkc

#11
##### Dec 20, 2010, 11:30 pm
Rob,
For last readings I sent you,

Battery---DMM---ACS 712---Adafruit Motorshield External Power Supply---H bridge (PWM) i.e. 1 L293Ds---2dc motors

When you say those readings are proportional to current and affectively represent current, do u mean following?

For a digital number of 1023 if Vref=5v
then,

Current or ADC or Voltage= 1023*Vref/2n

so for Vref=5v, Current=1023*5/1024=5A

or R u saying that current will increase as this Digital number increases and I will have to find the relation between them.
If I have to find the relation and evetually measure the values from DMM for the current, I wonder why they call it as a current sensor.

#12
##### Dec 21, 2010, 10:03 am
Quote
R u saying that current will increase as this Digital number increases and I will have to find the relation between them.

yes but the other way around

The digital number increases as the current increases

And you do have to find the relationship between the two. The data sheet details what this relationship should be, but you may have to callibrate as well.

Quote
If I have to find the relation and evetually measure the values from DMM for the current, I wonder why they call it as a current sensor.

Well AFAIK you can't measure current directly, you measure the voltage it causes across a resistor, or in the case of the 712 the internal hall effect device does the same thing.

All sensors are the same, a light sensor varies in resistance according to the light and you read this as a varying voltage, a temp sensor produces a variable voltage, it doesn't produce a temperature.

Technically I suppose the 712 should be called a "current to voltage converter" or something.

As for your problem, I really can't see why you would be getting such varying results now that I see what you have connected. If the motor speed and load are stable the current should be pretty stable as well. How you can get values from 0 to 220 I don't know.

Thinking...forget that last paragraph, what I said before about trying to measure the current on a PWM line still holds true I think. You're measuring the shield's external power supply that's used for the motor, the current being drawn from your battery will be in pulses as I described in the last post.

I'm certain that's what you problem is, and equaly certain I don't know how to measure it without things getting a lot more complicated.

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

#### mk3

#13
##### Dec 21, 2010, 01:45 pm
I have looked at this sensor a bit because they are used in products built by my employer.  Zero current will be 2.5V nominal.  The volt (signal) output will go up with current but the sensitivity is relatively low.  You need to look for the mV/A scale.

You may need to build a filter circuit and possibly an amplifier stage using an op-amp.  Look for circuits such as inverting amplifier or non-inverting amplifer using an opamp.  Look for RC circuits using a  resistor and capacitor.

Go Up