acs712

Posted on
  • Hi,

    I'm trying to interface my espruino with a ACS712 current detection board.

    I have the board sat between a source and a load, and have connected the out pin to C5 on my espruino. When using

    console.log(analogRead(c5));
    

    I get lots of values like this:

    0.49707789730
    pin
    C5
    0.49732204165
    pin
    C5
    0.49707789730
    pin
    C5
    0.49634546425
    pin
    C5
    0.49561303120
    

    But the values remain largely the same irrespective of whether the load is attached or not. I have read a couple of tutorials about using this board for arduino (here and here) but they seem to indicate that I just need to find some coefficient to multiply the values I'm reading by.

    Am I doing the right thing? Do I just have to find the "magic coefficient"?

  • You may have to read the datasheet for the ACS712. you should feed it with 5V and the output will be half of the supply voltage at no load, and as you apply a dc load you should expect the reading to change by 0.1V per Ampere (may vary depending on the version of the part).
    a change of 0.1V equals a change in reading of 0.1/3.3 = 0.0303, if your Espruino adc has 3.3V max range.
    Because the output signal has an offset that equals half of the supply voltage (5V) you need a stable 5V supply to get any accuracy.

  • Ah ok!

    So if I power the ACS712 from the VBAT pin from the board (I'm running from microUSB) that will keep it powered stably.

    I can then play around with the maths from there... Thanks for the help, I'll give it a go again later in the week.

  • the VBAT pin does not have a stable voltage, so the way I would do it is to use a second ADC input and two resistors. if for example you connect two resistors (with the same value) in series, from VBAT to GND, you get VBAT/2. Measure this signal (you get a reading from 0 to 1) and subtract the current sensor signal reading from this reading. Divide the result by 0.0303 and you get a reading in Amperes. This will give good accuracy even if the VBAT voltage drifts.
    Because the sensor can give out a signal that is higher than the 3.3V rating of the analog input pins of the Espruino you have to make sure you connect the current sensor to the load in a way that as the load increases, the output signal decreases. That way, you will apply VBAT/2 (about 2.1...2.5V) and lower to the analog pin. There should not be any risk that you exceed the maximum voltage for the analog input, unless the current flows in reverse for some reason.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

acs712

Posted by Avatar for MatB @MatB

Actions