Skip to content
ACS712

Electrical / Current

Interfacing ACS712 Electrical / Current with ESP32

What is the ACS712?

The ACS712 is a Hall-effect current sensor that measures AC or DC current without placing the microcontroller directly in the measured current path. Current flows through the module’s heavy-current terminals (IP+ and IP−); the sensor produces an analog voltage on OUT that changes with the magnetic field created by that current. On a typical 5 V module, the output sits near 2.5 V at zero current and moves up or down as current direction and magnitude change.

The practical details matter more than the basic hookup: choose the correct ±5 A, ±20 A or ±30 A variant, calibrate the zero-current voltage, and protect 3.3 V microcontroller ADC inputs from an output that can exceed 3.3 V.

ACS712 current-sensor breakout module. Check the silkscreen and exact variant before choosing the sensitivity constant.
ACS712 current-sensor breakout module. Check the silkscreen and exact variant before choosing the sensitivity constant.

ACS712 at a glance

Sensor supply
5 V DC for the ACS712 IC; breakout input details can vary
Measurement
AC and DC current, measured in series through IP+ / IP−
Output
Analog voltage; approximately VCC/2 at zero current
Current variants
±5 A, ±20 A or ±30 A
Typical sensitivity
185 mV/A (±5 A), 100 mV/A (±20 A), 66 mV/A (±30 A)
Microcontroller interface
Analog ADC input; no digital protocol or sensor library required
Internal conductor resistance
About 1.2 mΩ typical for the IC
Bandwidth
Up to 80 kHz typical; practical bandwidth depends on filtering and module design

Choose the correct ACS712 variant

VariantCurrent rangeTypical sensitivityTrade-off
ACS712-05B−5 A to +5 A185 mV/ABest signal change per amp; smallest range
ACS712-20A−20 A to +20 A100 mV/AMiddle range for many DC loads
ACS712-30A−30 A to +30 A66 mV/AWidest range, lower resolution per amp

Swipe sideways to see every column →

Module pins and current terminals

VCC
Power the module from its specified 5 V supply.
GND
Signal ground. Connect to the microcontroller ground.
OUT
Analog voltage output; connect to an ADC input only after checking the ADC voltage limit.
IP+
One end of the high-current path. Put this path in series with the source and load.
IP−
The other end of the high-current path. Current flowing IP+ to IP− makes OUT rise above its zero-current level.

How the ACS712 measures current

The measured current flows through a low-resistance copper conductor inside the IC. Its magnetic field is sensed by a Hall element, which produces a proportional analog voltage on OUT. The high-current conductor and signal pins are galvanically isolated inside the IC, but the safety of a finished module also depends on its PCB layout, terminal spacing, insulation and workmanship.

At zero current, OUT is nominally half the supply voltage (about 2.5 V with a 5 V supply). Current in one direction raises the output; reversing the current lowers it. The output is not a digital ampere value: the microcontroller must sample the voltage and calculate current using the sensitivity of the exact variant.

Calculate current from the output voltage

For a 5 V supply, use the following as a starting model:

Current (A) = (VOUT − VZERO) / sensitivity (V/A)

VariantSensitivity for the formula
ACS712-05B0.185 V/A
ACS712-20A0.100 V/A
ACS712-30A0.066 V/A

VZERO should be measured on your actual module with no current flowing. Do not assume it is exactly 2.500 V: offset, supply voltage, ADC reference and noise all affect the result. Averaging several samples at zero current improves the baseline. These values are typical datasheet sensitivities, not a substitute for calibration against a known current.

Warning

**Voltage and wiring safety:** IP+ and IP− are part of the measured current path and must be wired **in series** with the load, never in parallel across a supply. Disconnect power before changing this wiring and use terminals, wire gauge and fusing rated for the expected current. The ACS712 IC's internal isolation does not make an inexpensive breakout automatically safe for mains voltage. For mains measurements, use properly rated equipment and enclosure; do not handle exposed live wiring.

DC current versus AC current

For DC current, read OUT, convert the ADC reading to voltage, subtract the calibrated zero-current voltage and divide by the variant sensitivity. The sign indicates current direction; a small negative or fluctuating reading at zero current is usually offset and noise.

For AC current, the signal swings around its zero-current midpoint. Sampling only once per cycle or using the DC formula on one sample does not give AC RMS current. Sample fast enough to capture the waveform, remove the measured midpoint, calculate the root-mean-square of the samples and calibrate the result against a known AC current. The ADC sampling rate, analog filtering and waveform frequency determine usable accuracy.

Where it is useful

  • DC load monitoring: measure current drawn by a battery-powered load within the selected module's range.
  • Motor experiments: observe changes in motor current as load or speed changes.
  • AC load measurement: sample the waveform and calculate RMS current in software.
  • Overcurrent experiments: compare measured current with a threshold and trigger a warning or shutdown in the controller.
  • Energy-monitoring prototypes: pair current measurements with a separately measured voltage if power is required.

The ACS712 measures current, not voltage or energy by itself. Accurate power measurement needs voltage measurement and suitable sampling/calibration as well.

Troubleshooting

SymptomLikely causeWhat to check
Current is not near zero with no load currentZero-current offset, noise or ADC scaling errorMeasure OUT with no current flowing and update ZERO_CURRENT_V; average samples.
Current magnitude is wrong by a consistent factorWrong sensitivity constant or ADC referenceConfirm the 5 A / 20 A / 30 A variant and match the code to it.
Reading changes in the wrong directionCurrent direction is reversedCheck whether current flows IP+ to IP−; reverse the high-current path if appropriate.
ESP32 readings clip or the board resetsOUT exceeds the ADC's permitted voltage or wiring is noisyAdd a correctly calculated voltage divider, share signal ground and keep wiring short.
AC reading is unstable or too lowSampling too slowly, wrong RMS calculation or poor calibrationSample the waveform at a suitable rate, remove the midpoint and calculate RMS.
Output is noisy near a motorSwitching noise and magnetic interferenceSeparate signal wiring from motor leads, use appropriate filtering and average samples.

Frequently asked questions

Can the ACS712 measure both AC and DC? Yes. Its analog output changes with current in either direction. DC is calculated from the offset; AC current requires waveform sampling and an RMS calculation for an RMS value.

Does OUT read 0 V when no current flows? No. With a 5 V supply, it is nominally near 2.5 V. Calibrate the actual zero-current value on your module.

Can I connect OUT directly to an ESP32? Do not assume it is safe. The ACS712 is powered from 5 V and its output can exceed 3.3 V, depending on variant and current. Use a properly designed divider or suitable signal-conditioning stage so the full possible output remains within the ADC limits.

Which variant should I choose? Choose the lowest range that safely covers the expected peak current. The ±5 A variant has the highest sensitivity; the ±30 A variant covers more current but produces a smaller voltage change per amp.

Does it provide watts or energy directly? No. It measures current. Power requires voltage measurement too, and energy requires integrating power over time.

Is the module safe for mains? Do not judge safety by the IC's isolation rating alone. The complete board, terminals, spacing, enclosure and installation must be appropriately rated.

Continue with a board integration: ACS712 with Arduino Uno · ACS712 with ESP32

Setting Up ACS712 with ESP32

Read DC current from an ACS712 with a classic ESP32 DevKit. The sensor needs 5 V, while the ESP32 ADC input is not 5 V tolerant, so OUT must pass through a correctly sized voltage divider before reaching GPIO34. This example calibrates the zero-current baseline and converts changes at the ADC pin back to the sensor output voltage.

Warning

**Do not connect ACS712 OUT directly to an ESP32 GPIO.** Use a divider or suitable signal-conditioning stage and confirm the maximum voltage remains below the ADC input limit, including supply tolerance and current range. The example below assumes a divider ratio of 0.60; the resistor values and code must match the divider you actually build.

ACS712 to ESP32

ACS712 pinESP32 connectionImportant note
VCC5V / VINACS712 needs a 5 V supply; do not power it from 3V3.
GNDGNDCommon signal ground with ESP32 and divider.
OUTThrough a divider to GPIO34Example: 20 kΩ from OUT to GPIO34 and 30 kΩ from GPIO34 to GND; verify the maximum ADC voltage stays safely below 3.3 V.
IP+ / IP−In series with the loadThis is the measured current path, not a connection to GPIO.

Swipe sideways to see every column →

C++
  1. 1Disconnect all power before wiring the circuit.
  2. 2Power ACS712 VCC from 5 V / VIN and connect GND to ESP32 GND.
  3. 3Build the voltage divider between OUT and GPIO34. The example assumes 20 kΩ from OUT to GPIO34 and 30 kΩ from GPIO34 to GND; verify the ratio and voltage margin before powering up.
  4. 4Route IP+ and IP− in series with the load, using suitable terminals and wiring.
  5. 5Keep measured current at 0 A during startup so the code can capture the zero-current baseline.
  6. 6Upload the sketch, open Serial Monitor at 115200 baud, and test with a known safe DC load.

Expected output

Serial Monitor shows the voltage at GPIO34 and the calculated DC current. At zero current, the calculated current should be close to 0 A after startup calibration. The ESP32 ADC is not a precision voltmeter; for reliable results, calibrate its voltage conversion and verify current against a known load.

Troubleshooting

  • ESP32 resets or ADC reads incorrectly: disconnect power and check the divider and common ground before reconnecting.
  • Current is scaled incorrectly: confirm the divider ratio and ACS712 sensitivity constant both match the hardware.
  • Noisy measurements: average more samples, shorten wires and separate signal wiring from motor leads.
  • Negative current: current may be flowing IP− to IP+; the sign represents direction.
  • AC current: this sketch reads a DC offset change. For AC RMS, sample the waveform and calculate RMS after removing the calibrated midpoint.

Related Components

Related Guides & Projects