ESP32 - ACS712 Current Sensor
This tutorial instructs you how to use ESP32 to read the current that flows through a load with the ACS712 30A current sensor module, and print it in amps to the Serial Monitor. We start with a 12V DC device, such as a DC motor, LED strip or lamp, and at the end of the tutorial we change the code to measure AC current as an RMS value.

Knowing the current tells you a lot about a device. A motor that suddenly pulls twice its normal current is probably stuck, a battery charger that drops to almost zero is finished, and a heater that pulls nothing has a broken element. The ESP32 can watch this number for you and, later, send it to your phone over WiFi.
This tutorial shows how to program the ESP32 using the Arduino language (C/C++) via the Arduino IDE. If you’d like to learn how to program the ESP32 with MicroPython, visit this ESP32 MicroPython - ACS712 Current Sensor tutorial.
Hardware Used In This Tutorial
Or you can buy the following kits:
| 1 | × | DIYables ESP32 Starter Kit (ESP32 included) | |
| 1 | × | DIYables ESP32 S3 Starter Kit (ESP32 S3 included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Introduction to ACS712 Current Sensor
The ACS712 from Allegro measures current with the Hall effect. Inside the chip, the current passes through a thick copper path. This current makes a magnetic field, and a Hall sensor placed right next to the path turns that field into a voltage. Because nothing is wired between the copper path and the sensor side, the circuit you measure stays electrically isolated from the ESP32. The copper path is also very short, about 1.2 mΩ, so putting the sensor in a circuit almost does not change it.
The chip comes in three current ranges. They look the same, but each one gives a different voltage per amp. This tutorial uses the 30A version.
| ACS712 5A | ACS712 20A | ACS712 30A | |
|---|---|---|---|
| The current range | -5A to +5A | -20A to +20A | -30A to +30A |
| The sensitivity | 185 mV per amp | 100 mV per amp | 66 mV per amp |
| ACS712 30A (ACS712ELCTR-30A-T) | |
|---|---|
| The supply voltage | 5V (4.5V to 5.5V) |
| The measured current | DC and AC, -30A to +30A |
| The output at 0A | about 2.5V (half of the supply) |
| The output at +30A / -30A | about 4.48V / about 0.52V |
| The bandwidth | 80 kHz |
| The total output error | about ±1.5% at 25°C |
| The isolation voltage | 2.1 kV RMS |
| The current path resistance | about 1.2 mΩ |
The output is ratiometric. It means the output follows the real supply voltage: if the 5V line is actually 4.9V, the zero point moves to about 2.45V. This is why the code measures the zero point at startup instead of trusting the 2.5V number.
ACS712 Pinout

The module has two sides. A 3-pin header on one side goes to the ESP32:
- VCC pin: connect this pin to 5V. On the ESP32 board, use the VIN pin (it gives about 5V when the board is powered by USB). Do not use the 3.3V pin, the sensor needs 5V.
- GND pin: connect this pin to GND (0V) of the ESP32
- OUT pin: the analog output voltage. Connect this pin to an analog pin of the ESP32 through a voltage divider (see the wiring below)
A 2-pin screw terminal on the other side carries the current you want to measure. Some boards print IP+ and IP- next to it, some print nothing. This terminal must be in series with the load: cut one power wire of the load and put the terminal in the gap, so all the load current flows through the module. When the current flows from IP+ to IP-, the reading is positive. If your reading is negative, just swap the two wires. A small LED on the board shows that the module has power.
Is the 30A Version Good for Small Currents?
Not really. The 30A version changes only 66mV for each amp. With the 12-bit ADC of the ESP32 and our divider, one ADC step is about 17mA in theory, but the ESP32 ADC is noisy, so the reading moves by ±50 to ±100mA even when nothing flows. This is normal. The sensor is a good fit for loads of about 0.5A and more, such as motors, lamps, LED strips, heaters and chargers. The code averages many samples to make the value calmer. For small loads like a single LED, choose the 5A version.
※ NOTE THAT:
Mains AC (110V/220V) is dangerous and can kill. While you learn, use a low-voltage DC load like the 12V DC device in this tutorial. The copper side and the screw terminal of the module carry the full voltage of the load, so never touch them or the wires while a mains circuit is live.
How the ESP32 Turns the Voltage into Amps
At 0A the OUT pin sits at the zero voltage (about 2.5V). Current in one direction pushes it up, current in the other direction pulls it down, by 0.066V for every amp. So the formula is:
current (A) = (Vout - Vzero) / 0.066
For example, if the zero voltage is 2.47V and the OUT pin now shows 2.53V, the current is (2.53 - 2.47) / 0.066 = 0.91A.
There is one more step for the ESP32. The OUT pin can go up to about 4.5V, but an ESP32 analog pin only accepts up to 3.3V. A 10kΩ and a 20kΩ resistor divide the voltage to two-thirds before it reaches the pin, so 4.5V becomes 3.0V. In the code, we multiply the pin voltage by 1.5 to get the real OUT voltage back.
Wiring Diagram between ACS712 and ESP32
Power the ACS712 from the VIN pin of the ESP32 (5V from USB). The OUT pin goes through the 10kΩ resistor to GPIO36, and a 20kΩ resistor goes from GPIO36 to GND. We use GPIO36 because it belongs to ADC1. The ADC2 pins of the ESP32 stop working when WiFi is on, so ADC1 pins (GPIO32 to GPIO39) are the safe choice if you add WiFi later. GPIO34 also works.
On the load side, the 12V adapter feeds the DC device through the DC power jack, and the positive wire of the DC device passes through the screw terminal of the ACS712. The 12V never touches any pin of the ESP32.
- How to connect ESP32 and ACS712 current sensor using breadboard

This image is created using Fritzing. Click to enlarge image
- How to connect ESP32 and ACS712 current sensor using screw terminal block breakout board

| From | To |
|---|---|
| ACS712 VCC | ESP32 VIN (5V) |
| ACS712 GND | ESP32 GND |
| ACS712 OUT | 10kΩ resistor, other end to GPIO36 |
| GPIO36 | 20kΩ resistor, other end to ESP32 GND |
| 12V adapter + (via DC power jack) | ACS712 IP+ terminal |
| ACS712 IP- terminal | DC device + wire |
| DC device - wire | 12V adapter - (via DC power jack) |
If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: The best way to Power ESP32 and sensors/displays.
How To Program for ACS712 Current Sensor
No library is needed. The ESP32 core already has everything.
- Read the analog pin in millivolts. The analogReadMilliVolts() function uses the calibration data stored in the ESP32, so it is more accurate than analogRead() with a simple formula:
- Undo the voltage divider to get the OUT voltage of the sensor:
- At startup, with the load OFF, average 1000 readings and keep the result as the zero voltage:
- Average a few hundred readings, then turn the voltage into amps:
ESP32 Code - ACS712 DC Current
Quick Instructions
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE.
- Do the wiring as above image. Double-check the two resistors: 10kΩ between OUT and GPIO36, 20kΩ between GPIO36 and GND.
- Switch the load OFF (leave the 12V adapter unplugged) before you power the ESP32.
- Connect the ESP32 board to your PC via a USB Type-C cable.
- Open Arduino IDE on your PC.
- Select the right ESP32 board (e.g. ESP32 Dev Module) and COM port.
- Copy the above code and open with Arduino IDE.
- Click to the Upload button on Arduino IDE to upload code to ESP32.
- Open the Serial Monitor and wait for the "Zero voltage" line.
- Now plug in the 12V adapter to turn the DC device on, and watch the current.
The first lines are the idle noise: the value jumps by a few hundredths of an amp around zero. With a 12V DC motor as the DC device, the current goes up to about 1A when the motor starts. Hold the motor shaft gently with your fingers and the current rises, because a motor under load pulls more current. Unplug the adapter and it goes back to about zero.
※ NOTE THAT:
If the value stays far from zero with the load OFF, the ESP32 was started while current was flowing. Turn the load off and press the EN (reset) button on the ESP32 to calibrate again.
Measuring AC Current with ESP32 and ACS712
With AC, the current changes direction 50 or 60 times per second, so the OUT voltage swings up and down around the zero voltage. An average of these samples would be close to zero and tell us nothing. Instead, we measure the RMS value, which is the number a multimeter shows for AC:
- Read the sensor again and again for 200ms. This covers 10 cycles at 50Hz or 12 cycles at 60Hz.
- For each sample, take the difference from the zero voltage and square it.
- RMS current = square root of (the average of all the squares) / 0.066
The wiring stays the same. Only the load changes, for example a lamp or a fan on mains power.
※ NOTE THAT:
Again: mains AC is dangerous. Only measure a mains load if you know how to work with it safely, keep the screw terminal and wires covered, and never touch them while the circuit is plugged in.
Quick Instructions
- Turn the AC load OFF before you power the ESP32, so the zero point is correct.
- Copy the above code and open with Arduino IDE.
- Click Upload button on Arduino IDE to upload code to ESP32.
- Turn the AC load on and see the result on Serial Monitor:
With no load, the noise still gives a small RMS value of a few hundredths of an amp, because RMS turns every bit of noise into a positive number. Keep this in mind when you read small AC currents.
Video Tutorial
Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.