Source: https://mokxi.com/libraries/acs712
Updated: 2026-11-02

Libraries / Sensors
Arduino library · Sensors

# ACS712: current in milliamps from a Hall sensor

The ACS712 is an Allegro Hall-effect current sensor: the current flows through a copper path inside the chip, and the chip outputs a voltage that sits at half the supply with no current and moves up or down with it. Rob Tillaart’s ACS712 library reads that voltage with analogRead() and turns it into milliamps, for direct current or for the RMS value of alternating current.

Open the example in the editor See the calls

Built in on Mokxi: #include <ACS712.h> and it builds, with nothing to install. Free, and no account needed.

## What ACS712 does

The constructor needs four numbers: the analog pin, the ADC’s reference voltage, the ADC’s maximum count and the sensor’s sensitivity in millivolts per amp. That last one is printed on the chip: 185 for the 5 A version, 100 for the 20 A and 66 for the 30 A. Use the wrong one and every reading is scaled wrong.

The zero point drifts a little from board to board, so call autoMidPoint() with no current flowing before you measure. A 5 A ACS712 moves only 185 mV per amp, about 38 counts on a 10-bit ADC, so readings under 100 mA are mostly noise.

Library Manager name | ACS712

Author | Rob Tillaart

Include | #include <ACS712.h>

Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Raspberry Pi Pico, Raspberry Pi Pico W, Seeed XIAO SAMD21, STM32, STM32 Nucleo-F411RE, Arduino Uno R4, ESP32 DevKit, ESP32-S3-DevKitC-1, ESP8266 NodeMCU, Arduino Pro Mini 3.3 V, Seeed XIAO ESP32-C3, Seeed XIAO ESP32-C6, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, Seeed XIAO ESP32-S3, Arduino Nano ESP32, Arduino Nano RP2040 Connect, Seeed XIAO RP2040, Waveshare RP2040-Zero, Arduino Uno R4 WiFi

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Current sensor, ACS712

## Install it

It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Raspberry Pi Pico, Raspberry Pi Pico W, Seeed XIAO SAMD21, STM32, STM32 Nucleo-F411RE, Arduino Uno R4, ESP32 DevKit, ESP32-S3-DevKitC-1, ESP8266 NodeMCU, Arduino Pro Mini 3.3 V, Seeed XIAO ESP32-C3, Seeed XIAO ESP32-C6, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, Seeed XIAO ESP32-S3, Arduino Nano ESP32, Arduino Nano RP2040 Connect, Seeed XIAO RP2040, Waveshare RP2040-Zero, Arduino Uno R4 WiFi.

In Mokxi it is built in: #include <ACS712.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ACS712" by Rob Tillaart from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ACS712 to lib_deps in PlatformIO. Mokxi follows the calls of release 0.4.1, so a sketch written here builds there too.

What to know in the simulator: Not listed for the ATtiny85: the library’s float sums and a Serial print come to 1.7 KB more than its 8 KB of flash.

Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### ACS712 ACS(A0, 5.0, 1023, 185)

A 5 A sensor on A0 of a 5 V board with a 10-bit ADC. On an ESP32 the reference is 3.3 and the maximum 4095.

### ACS.autoMidPoint()

Measures the output with no current and uses it as zero. Call it in setup() with the load switched off.

### ACS.mA_DC()

Direct current in milliamps, positive or negative with direction.

### ACS.mA_AC(50)

The RMS of an alternating current at 50 Hz (60 in North America), sampled over whole cycles.

### ACS.mA_peak2peak()

The difference between the highest and lowest current over a cycle.

### ACS.getMidPoint()

The ADC count the library treats as zero amps, worth printing while you calibrate.

### ACS.setNoisemV(43)

Tells the library how much noise to ignore, so tiny currents read as zero instead of wandering.

## Example: Amps through a load with an ACS712 and the ACS712 library

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 A0 to Current sensor, ACS712 OUT
- Arduino Uno R3 5V to Current sensor, ACS712 VCC
- Arduino Uno R3 GND to Current sensor, ACS712 GND
- Power VCC to Current sensor, ACS712 IP+
- Current sensor, ACS712 IP- to Resistor 1
- Resistor 2 to Ground GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### The current is three times too high or too low

The sensitivity in the constructor does not match the chip. Read the marking on the module: ELC-05B is 185 mV/A, ELC-20A is 100 and ELC-30A is 66.

### It reads a few hundred milliamps with nothing connected

The zero point is off. Call autoMidPoint() with no current flowing, and on a noisy supply average several readings or raise setNoisemV().

### Readings saturate on an ESP32 or other 3.3 V board

The module runs on 5 V and its output can reach 5 V, above a 3.3 V pin’s limit. Put a divider on the output and change the constructor’s voltage, or use a 3.3 V current sensor such as the INA219.

## Projects that use ACS712

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Motor current meter An ACS712 in a 6 V gear motor’s lead and a 16x2 I2C LCD: the current now and the highest seen, with the start-up surge a motor draws before it gets going.

## Keep going

### Learn

- Arduino ACS712 Current Sensor: Wiring and Code

### Parts

- Current sensor, ACS712

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- Adafruit MPU6050
- BME280

Every built-in library · Open the editor

## Try ACS712 without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
