Working Principle
The ACS712 from Allegro MicroSystems is an integrated Hall-effect current sensor. A low-resistance copper conduction path runs through the IC package; current flowing through this path generates a magnetic field, which a linear Hall element detects. An on-chip amplifier outputs an analog voltage that is linearly proportional to current, centered at VCC/2 (2.5 V at 5 V supply) for bidirectional measurement.
Electrical Characteristics
ACS712 Key Specifications
| Parameter | 5A Variant | 20A Variant | 30A Variant |
|---|---|---|---|
| Sensitivity | 185 mV/A | 100 mV/A | 66 mV/A |
| Supply Voltage | 4.5–5.5 V DC | ||
| Zero-Current Output | VCC/2 (~2.5 V) | ||
| Bandwidth | 80 kHz | ||
| Internal Resistance | 1.2 mΩ | 1.2 mΩ | 1.2 mΩ |
| Isolation | 2.1 kV RMS (galvanic) | ||
| Total Output Error | ±1.5% (typical) | ||
Interfacing with an MCU
The ACS712 breakout has 3 pins: VCC (5 V), GND, and OUT (analog voltage). Connect OUT to an ADC pin. For 3.3 V MCUs, use a voltage divider (e.g., 10 kΩ + 6.8 kΩ) to scale the 0–5 V output to 0–3.3 V range, or use an op-amp buffer.
Calibration
At zero current, the output should be exactly VCC/2 (2.500 V). In practice, offset varies ±25 mV unit-to-unit. Calibrate by reading the ADC with no load and storing the offset value. For AC current measurement, sample at ≥10× the AC frequency and compute RMS from the sample set.
Code Example
// ACS712 (5A) current sensor — DC measurement on Arduino
#include <Arduino.h>
#define ACS_PIN A0
#define SENSITIVITY 0.185 // V/A for 5A variant
#define V_REF 5.0
#define ADC_STEPS 1023.0
#define SAMPLES 200
float zero_offset = 2.5; // Calibrated at startup
void setup() {
Serial.begin(115200);
delay(1000); // Let sensor stabilize
// Calibrate zero point (NO current flowing!)
float sum = 0;
for (int i = 0; i < SAMPLES; i++) {
sum += analogRead(ACS_PIN) * (V_REF / ADC_STEPS);
delayMicroseconds(500);
}
zero_offset = sum / SAMPLES;
Serial.print("Calibrated zero offset: ");
Serial.println(zero_offset, 4);
}
void loop() {
float sum = 0;
for (int i = 0; i < SAMPLES; i++) {
sum += analogRead(ACS_PIN) * (V_REF / ADC_STEPS);
delayMicroseconds(500);
}
float voltage = sum / SAMPLES;
float current = (voltage - zero_offset) / SENSITIVITY;
Serial.print("V="); Serial.print(voltage, 3);
Serial.print("V I="); Serial.print(current, 3);
Serial.println("A");
delay(500);
}
Real-World Applications
Solar Panel Maximum Power Point Tracking
MPPT charge controllers use Hall-effect current sensors like the ACS712 to continuously monitor panel output current and voltage. By perturbing the operating point and measuring the resulting power change, the controller finds the maximum power point — extracting 20–30% more energy than simple PWM controllers.
Limitations
- 5 V only: The ACS712 requires a 5 V supply; not natively compatible with 3.3 V MCUs without level shifting.
- Noise floor: ~20 mV peak-to-peak noise limits accuracy below ~100 mA. Use oversampling and averaging.
- Temperature drift: Sensitivity changes ~0.012%/°C. For precision, use the INA219 (digital, I2C) instead.
- No AC RMS: Raw analog output is instantaneous; computing RMS for AC requires high-frequency sampling and math in firmware.