Arduino UNO + ACS712

Closeup of Arduino UNO with ACS712

I have an ACS712 current sensor breakout board (±20A variant) that I want to use with the Blue Pills. However, ACS712 outputs 5V analog, so I would need to set a voltage divider, because Blue Pill boards can only read 3.3V max. So before doing all that work, I want to make sure that the ACS712 board is usable. I am going to test it with Arduino UNO.

As usual with Arduino, the setup was fairly straightforward. Here’s the wiring diagram:

Wiring diagram
In Fritzing, the ACS712 breakout board is red. Mine is actually blue. In the diagram above, the battery is 9V, my test actually used a 12V lead acid battery.

Here’s the schematic.

Schematic

For the code, I just used the ACS712_20_DC_DEMO example from the ACS712 library by Rob Tillaart. From Arduino IDE: File → Examples → ACS712 → ACS712_20_DC_DEMO. I modified the print statements a bit:

//    FILE: ACS712_20_DC_DEMO.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo to set midpoint and mVperAmpere for class.
//    DATE: 2020-03-18
//    (c) : MIT

#include <ACS712.h>

// Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
// ACS712 5A  uses 185 mV per A
// ACS712 20A uses 100 mV per A
// ACS712 30A uses  66 mV per A

ACS712  ACS(A0, 5.0, 1023, 100);

void setup()
{
  Serial.begin(115200);
  Serial.println(__FILE__);
}

void loop()
{
  int mA = ACS.mA_DC();
  Serial.print("DC current = "); Serial.print(mA); Serial.println(" mA");

  if (Serial.available() > 0)
  {
    char c = Serial.read();
    if (c == '+') ACS.incMidPoint();
    if (c == '-') ACS.decMidPoint();
    if (c == '0') ACS.setMidPoint(512);
    Serial.print("Mid point = "); Serial.println(ACS.getMidPoint());

    if (c == '*') ACS.setmVperAmp(ACS.getmVperAmp() * 1.05);
    if (c == '/') ACS.setmVperAmp(ACS.getmVperAmp() / 1.05);
    Serial.print("mV / A = "); Serial.println(ACS.getmVperAmp());
  }
  delay(1000);
}

The Arduino IDE setup was:

  • Board: “Arduino Uno”
  • Port: “/dev/ttyACM0 (Arduino Uno)”

After all set, I clicked the upload button in Arduino UNO. After the upload was complete, I opened the serial monitor. The relevant part of the serial monitor output:

DC current = -195 mA
DC current = -195 mA
DC current = -195 mA
DC current = -146 mA
DC current = -146 mA
DC current = -195 mA
DC current = -146 mA
DC current = -293 mA
DC current = 586 mA
DC current = 586 mA
DC current = 439 mA
DC current = 537 mA
DC current = 537 mA
DC current = 488 mA
DC current = 635 mA
DC current = 488 mA
DC current = 537 mA
DC current = 391 mA
DC current = 488 mA
DC current = 537 mA
DC current = 488 mA
DC current = 537 mA
DC current = 488 mA

That’s … wild 🤔.

Notice the initial negative reading. That was before I connected the battery. The reading became positive after I connected the battery. The reading when current was not flowing was off between -146mA to -293mA. It should read around 0mA.

The battery that I used is an old 12V lead acid battery that’s unable to hold its charge. The battery voltage immediately drops to around 7V after connected to the load. However, even accounting all these the reading was still off. Battery with 7V voltage connected to 10Ω load should let about 700mA of electric current to flow. The reading from the serial monitor above was between 391mA to 635mA.

Arduino UNO with ACS712
Actual reading was around 719mA.

This ACS712 breakout board that I used can read ±20A of current, so I was not expecting it to be accurate, but this is pretty bad. I don’t think I want to use this ACS712 board for low current application. The INA219 breakout board is definitely better for low current application.

Laters!

One response on “Arduino UNO + ACS712