ACS712 current sensor

Development & General Chat for the superb openxvario project.

Moderator: rainer

Post Reply
benoit
Posts: 4
Joined: Tue Sep 06, 2016 6:55 am
Country: -

ACS712 current sensor

Post by benoit »

Hello,
I have tried several configurations with openxsensor.
First a variometer : it seems to work ! Great !! But the precision is only 1m. I guess that my sensor is a low resolution one...

Secondly a ACS712 current sensor.
With almost no load it gives me a 42A value...
I have several questions :
1) I uses openxsensor v7.0 : there is no more calibration values for the current sensor (min value, max value...) Is it the right version to use ?
2) I have measured a value of 4.82V for the VCC. I was expecting 5V. Is this value acceptable ?
3) I have measured the voltage at the output pin of the ACS712 when almost no current is applied (less than 1A), I read 2.42V (so almost VCC / 2). I have read somewhere that this is the correct behaviour of the ACS712. Question : is it taken into account in the openxsensor code ?
4) I have read somewhere that a 47nF capacitor could increase the precision. It should be solder between GND and output. Correct ?

If I success in making it works, I will try to make a lipo voltage checker by monitoring the lipo cells (using voltage dividers), and then use 2 current sensors in parallel in order to be able to measure more than 30A.

Thanks

User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: ACS712 current sensor

Post by jhsa »

If you want to measure more current you need a different sensor. Connecting 2 in parallel doesn't work :) they would both read the same current as far as I know..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
rainer
Posts: 391
Joined: Tue Jan 01, 2013 9:20 pm
Country: Germany
Location: near Düsseldorf

Re: ACS712 current sensor

Post by rainer »

Hi benoit,
please check the description in the oxs_config_description.h file.

Code: Select all

* 6.4 - Current sensor  parameters   **************************************************************************************
*     It is possible to measure a current (and current consumption) if a current sensor is connected.
*     Connecting a current sensor is an optional feature.
*     It requires some additional hardware. It can be an IC like ACS712 (for 5, 20, 30 amp) or ACS758 (for 50, 100, 150, 200 amp).
*     Most sensors can read bidirectional currents but ACS758 has "U" types that read only unidirectional current (providing then an higher sensitivity).
*     Those current sensors are quite cheap (see e.g. ebay) and return a voltage that depends on the current. This voltage is measured by OXS via an analog pin.
*     The Pin value to enter in the oXs_config.h is a number from 0 up to 7 (0 means A0, 1 means A1, ...7 means A7).
*     If a current sensor is used, do not to use a pin that is already used by a voltage.
*  !! Take care that the voltage applied to Arduino pin may not exceed Vcc (normally 5 volt) or 1.1 volt (if internal reference voltage is used).
*     It can be that you have to use a voltage divider in order to reduce the voltage applied on Arduino pin.
*     See explanation above (6.2) about voltage divider.
*     Take care : do NOT use pins A4 and A5 if you use a vario or an airspeed (those pins are reserved for the barometric and pressure sensors).
* Note: The current sensor is normally powered by the 5 volt VCC from OXS (same as the vario sensor).
*       There are bidirectional sensor and unidirectional sensor.
*       For bidirectional, output is normally equal to VCC/2 when current = 0 Amp and, for unidirectional, output is normally 0,6 volt at 0 Amp.
*       If OXS is connected to a battery giving less than 5.2 volt, the supply voltage for the current sensor will vary with the OXS supply voltage.
*       Therefore VCC/2 ( = O amp) will varies with VCC.
*       This is an issue if the Arduino ADC is configured to use the 1.1 volt internal reference.
*       So, in this case it is better to configure the ADC in order to use VCC as reference for conversion.
*       In order to use a current sensor, you have to uncomment the line //#define PIN_CURRENTSENSOR and specify the Arduino pin connected to the current sensor. 
*       You must also define 2 parameters depending of the type of sensor being use; those parameters are given in the datasheet of the sensor).
*         - MVOLT_AT_ZERO_AMP  =  milliVolt generated by the sensor when current is 0 Amp: normal value is :
*                                       - for a bidirectional sensor  : Vcc from current sensor / 2 (so = 2500 if sensor is connected to Arduino Vcc and Arduino Vcc is 5 Volt).
*                                       - 600 for unidirectional sensor 
*         - MVOLT_PER_AMP       =  milliVolt per Amp. The value depend on the sensitivity of the sensor (e.g. an ACS712ELCTR-30A-T has a sensitivity of 66 mvolt/A, a ACS758LCB-050U has a sensitivity of 60 mv/Amp)
*        
*        If you use the 1.1 internal reference to measure voltagse and current, you must also use a voltage divider in order to scale down the voltage produced by the current sensor.
*        See the section 6.2 above about voltage divider. The principle are just the same but the names of the 2 paraameters are:
*          - RESISTOR_TO_GROUND_FOR_CURRENT
*          - RESISTOR_TO_CURRENT_SENSOR 
*  Note: those parameters are automatically discarded when PIN-CURRENTSENSOR is not defined (= set as comment).
*  Note: When current sensor is used, oXs can also calculate and transmit current consumption (milliAh) and Fuel (in % going down from 100% to 0%).
*        If you want the last one, then use a setup like "Fuel , MILLIAH , -100 , 4000 ,0" in "data to transmit section" (and replace 4000 by the capacity - in milliAmph - of your battery) (see below).
*        Still, with Tx using openTx or Ersky9x software, it is better to let the Tx calculates those values by it self based on the current. 
*               This ensure that values are consistent; it allows to reset the values on Tx side; it allows to change the value of the battery capacity on Tx side (so without having to reload another set up in Arduino oXs).    
*               E.g on Ersky9x, in Telemetry menu set up "current source"  set "FAS"; in "mAh Alarm", set the mah you want for alarm to sound and select warning sound/voice, 
*               ie 70% of 2200 mAh lipo, use 1540. then the FUEL percentage will start from 100% count down to 0% when 1540 is consumed.
************************************************************************************************************************
//#define PIN_CURRENTSENSOR      2
#define MVOLT_AT_ZERO_AMP        600
#define MVOLT_PER_AMP            60
#define RESISTOR_TO_GROUND_FOR_CURRENT  10
#define RESISTOR_TO_CURRENT_SENSOR      40
so it depends really on the type of current sensor you are using. your's seems to be a bidirectional one as the no load voltage is about vcc/2

the configuration i use for a -5A to +5A ACS712 is the following:

Code: Select all

//#define USE_INTERNAL_REFERENCE  // uncomment this line if you use 1.1 volt internal reference instead of Vcc
//#define USE_EXTERNAL_REFERENCE  // uncomment this line if you use an external reference instead of Vcc
#define REFERENCE_VOLTAGE 5005    // set value in milliVolt; if commented, oXs will use or 1100 (if internal ref is used) or 5000 (if internal ref is not used) 

......

#define PIN_CURRENTSENSOR   2
#define MVOLT_AT_ZERO_AMP              2500    // in millivolt
#define MVOLT_PER_AMP                  185      // in milliVolt per Amp
//#define RESISTOR_TO_GROUND_FOR_CURRENT  10   // put as comment or set to 0 if no divider is used
//#define RESISTOR_TO_CURRENT_SENSOR      40     // put as comment or set to 0 if no divider is used

Rainer
build your own vario ==> https://github.com/openXsensor/openXsensor/wiki (Formerly https://code.google.com/p/openxsensor/ and https://code.google.com/p/openxvario/)
benoit
Posts: 4
Joined: Tue Sep 06, 2016 6:55 am
Country: -

Re: ACS712 current sensor

Post by benoit »

Thank you Rainer
in the v7.0 these defines are not present anymore, but Yes indeed there are calibration parameters that I have not set properly
This is where my problem is, Thanks for your help

* 6.6 - Current sensor calibration parameters **************************************************************************
* Current sensor has normally to be calibrated based on 2 parameters :
* OFFSET_CURRENT_STEPS = Offset to apply for current; normal value is 1024/2 for a bidirectional sensor because 0 Amp gives VCC/2 (or 1.1 V/2 when using a divider).
* Still for unidirectional sensor, voltage at 0 amp is 0.6 volt for 5 volt Vcc; so offset should then normally be 1024 * 0.6 /5 = 123.
* MAMP_PER_STEP = milliAmp per step from Analog to Digital Converter; the value depend on the sensitivity of the sensor (and on an eventual voltage divider).
* If no divider is used, the value of MAMP_PER_STEP is normally equal to V (in mvolt) / (sensitivity in mV/Amp * 1.023) where:
* - V is Vcc (e.g. 5000) or internal 1.1 ref (e.g. 1100) depending on the reference you use
* - Sensitivity is normally given in the datasheet from your sensor.
* E.g. For a ACS758LCB-050U, sensitivity is 60 mv/Amp
* So if using 5 volt Vcc => 5000 / (60 * 1.023) = 81.5.
* Note: those parameters are automatically discarded when PIN-CURRENTSENSOR is not defined (= set as comment).
************************************************************************************************************************

João
If I use 2 sensors in parallel, I will measure 2 currents I1 and I2. (probably equal to I / 2 if the sensors are identical)
Then I will modify the source code to read the value on 2 pins and then make the sum.
I didn't find any arduino sensor based on ACS758 chip. And I already have spare ACS712 sensors that I'd like to use.
User avatar
kalle123
Posts: 905
Joined: Sat Mar 29, 2014 10:59 am
Country: -
Location: Moenchengladbach

Re: ACS712 current sensor

Post by kalle123 »

benoit wrote: 4) I have read somewhere that a 47nF capacitor could increase the precision. It should be solder between GND and output. Correct ?
Those sensors have capacitors installed on the shield. Left one original, right a bit reduced .... ;)
Bildschirmfoto74.jpeg

mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: ACS712 current sensor

Post by mstrens »

I changed the parameters for current sensor in V7 in order to make them easier to calculate for a common user.

If you put 2 sensors in parallell, the total current will be splitted between the 2 sensors but it could be that one sensor get much more current than the other. It will depend on the resistance of each set of components. Please note that the resistor is not only the internal resistor of the sensor but also the resistors of the wires, the soldering. In the worst case nearly all the current could go via only one sensor and so you will not really be able mesure twice the max current of a sensor.
In order to get nearly the same current in each sensor, it could be that you have add an extra resistor in each branch in order to balance them. For sure it must then be very very low resistors.
benoit
Posts: 4
Joined: Tue Sep 06, 2016 6:55 am
Country: -

Re: ACS712 current sensor

Post by benoit »

my mistake i am in version 2.5 this is why i don't have the same configuration parameters
benoit
Posts: 4
Joined: Tue Sep 06, 2016 6:55 am
Country: -

Re: ACS712 current sensor

Post by benoit »

Yes 2 sensors in // could be complicated. I will look at ACS758...
Thank you for your help and the job done on this project !
User avatar
rainer
Posts: 391
Joined: Tue Jan 01, 2013 9:20 pm
Country: Germany
Location: near Düsseldorf

Re: ACS712 current sensor

Post by rainer »

here is the "old" image from the add-on capacitor that was previously added to the acs current sensor:
ACS712WithCapacitor.JPG
ACS712WithCapacitor.JPG (45.04 KiB) Viewed 7973 times
the capacitor used was a small 47nF SMD capacitor. Don't know if it is still required for "today's" versions, put it greatly reduced noise at that time...
Rainer.
build your own vario ==> https://github.com/openXsensor/openXsensor/wiki (Formerly https://code.google.com/p/openxsensor/ and https://code.google.com/p/openxvario/)

Post Reply

Return to “OpenXVario - an open source vario supported by the open source firmwares!!”