Current sensor, ACS712
A Hall sensor beside a strip of copper in series with the load: 2.5 V at no current, 185, 100 or 66 mV an amp.
- 5 pins
- 2 settings
- In 1 project
- In 1 lesson
The Current sensor, ACS712 in brief
What it is, and every setting the properties panel gives it.
The ACS712 is Allegro’s Hall-effect current sensor on the red kit breakout: a screw terminal, IP+ and IP-, in series with the load, and VCC, OUT and GND for the board. The current flows through 1.2 milliohms of copper, isolated from the electronics. It needs 4.5 to 5.5 V, so on an Uno it goes to 5 V with OUT on A0; on an ESP32 power it from 5 V and divide OUT down, since it rests at 2.5 V and swings toward 5 V. Mokxi models the output as half the supply plus 185, 100 or 66 mV an amp for the -05B, -20A and -30A models, ratiometric, so a 4.8 V USB rail moves the zero to 2.4 V. The noise is the datasheet’s 21, 11 and 7 mV peak to peak, drawn 4000 times a second, so an Uno’s reading jumps a few counts and sketches average; one count is 26 mA on the 5 A board. Rob Tillaart’s ACS712 library compiles. The classic mistake is calling autoMidPoint() while the load already runs. The offset error, drift, nonlinearity near full scale, the breakout’s 1 nF filter and heating of the copper are not modeled.
- Family
- Sensors
- Pins
- 5
- model
- ACS712-05B (or ACS712-20A, ACS712-30A, ACS758LCB-050B, ACS758LCB-050U, ACS758LCB-100B, ACS758LCB-100U, ACS724LLCTR-05AB, ACS724LLCTR-10AB, ACS724LLCTR-20AB, ACS724LLCTR-30AB, ACS724LLCTR-50AB)
- noise
- true
5 pins
Named as the editor names them, so a wire lands where you expect it.
OUT.U part).How to use the ACS712 current sensor with an Arduino
VCC to 5 V, GND to GND and OUT to A0. The screw terminal goes in series with the load: here the bench supply’s plus runs through a push button to IP+, and IP- goes on to the motor. Current into IP+ raises OUT from 2.5 V by 185 mV an amp on the 5 A board.
The ACS712 library does the sums: ACS712 ACS(A0, 5.0, 1023, 185), then ACS.autoMidPoint() in setup and ACS.mA_DC(10) for an averaged reading. Call autoMidPoint() while nothing flows, which is why the motor here waits for the button. With the motor already on, its current becomes the zero. One count on an Uno is 26 mA, and the noise moves the reading by a few counts, so always average.
The ACS712 needs 4.5 to 5.5 V, so on an ESP32 power it from 5 V and put a divider on OUT: it rests at 2.5 V and passes 3.3 V above about 4.3 A on the 5 A board.
#include "ACS712.h"
ACS712 ACS(A0, 5.0, 1023, 185);
void setup() {
Serial.begin(115200);
ACS.autoMidPoint(); // with nothing flowing yet
}
void loop() {
Serial.println(ACS.mA_DC(10));
delay(200);
}What is true about the Current sensor, ACS712, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
From the Allegro ACS712, ACS758xCB and ACS724 datasheets:
The output. OUT = zero + sensitivity x current: 2.5 V at no current on 5 V,
and the model's millivolts more for each amp from IP+ to IP-, less for each amp
the other way. A 2 A load on the ACS712 5 A board reads 2.87 V. A unidirectional
part (U) starts at 0.6 V on 5 V and reads current one way only.
Ratiometric. Both the zero and the sensitivity are in proportion to the supply. On a USB port's 4.8 V the zero is 2.4 V and the 5 A board gives 177.6 mV an amp. (The ACS724's sensitivity moves 1.3 times as much as the supply, as its datasheet gives.) A sketch that reads the converter against the same supply cancels most of that; one that assumes 2.5 V reads a current that is not there.
The noise. 21, 11 and 7 mV peak to peak for the three ACS712 models, a new value 4000 times a second, which is the figure and the 2 kHz bandwidth the datasheet quotes it at. The ACS758's are its datasheet's 10, 15, 6 and 12 mV (three sigma either way), and the ACS724's its 150 µA per root hertz over the same 2 kHz, about 8 mA. On an Uno one converter step is 4.9 mV, so the ACS712 5 A board's reading jumps by a few steps and the 30 A board's by about one. Average a hundred readings and it settles.
The resolution. One step on a 5 V, 10-bit converter is 26 mA on the ACS712 5 A board, 49 mA on the 20 A and 74 mA on the 30 A, and 122 mA on the ACS758 50 A. Small currents need the 5 A board, the ACS724 5 A (12 mA a step), or an INA219.
Not modeled
The common ACS712 board's filter capacitor is 1 nF, which leaves more of the chip's 80 kHz bandwidth, and more noise, than the datasheet's 2 kHz figure: a real board jumps more than this one. The chip's offset (here the zero is exactly half the supply; a real one is a few millivolts off, which is why sketches measure it), the 1.5% total error, temperature drift, the nonlinearity near full scale, where the output stops past full scale (here at the rails), the microseconds of response time, the ACS758's extra error away from 5 V, and the heating of the copper are not modeled.
From ACS712 current sensor, in full.
See the Current sensor, ACS712 in a project
One built-in project uses it. It opens in the editor, already wired.
Where it turns up in a lesson
One lesson places it in its own circuit.
The boards it is shown on
This board has a built-in project with the Current sensor, ACS712 in it.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Current sensor, ACS712
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.