A hall effect current sensor outputs an analog voltage proportional to the magnetic field generated by the current flowing through its internal conductor. For a standard 3.3V ESP32 setup using an ACS724 (20A range), the output is a ratiometric analog voltage centered at 1.65V (VCC/2), yielding a raw ADC reading of ~2048 at zero current. To get physical amperes, you subtract this zero-offset voltage from the measured voltage and divide by the sensor's specific sensitivity (e.g., 100 mV/A).

The Physics: How Hall Effect Current Sensing Works

When current flows through the primary copper conductor inside the sensor IC, it generates a concentric magnetic field. A Hall element—a thin semiconductor wafer positioned adjacent to this conductor—experiences the Lorentz force. This force deflects charge carriers within the semiconductor, creating a transverse voltage differential known as the Hall voltage, which scales linearly with the magnetic field strength.

This microvolt-level Hall signal is immediately amplified by an internal op-amp and output as an analog voltage. Because the magnetic field couples across an air gap or insulating compound within the IC packaging, the measurement circuit is galvanically isolated from the primary current path. This allows a 3.3V microcontroller to safely measure high-side or low-side currents on a 12V, 24V, or even 120V AC load without sharing a ground reference, provided the IC's isolation rating is not exceeded.

Sensor Selection and Pinout Specifications

Not all hall sensors are created equal. The legacy ACS712 was designed for 5V logic and is notoriously noisy on 3.3V microcontrollers. Modern designs like the ACS724 or industrial modules from LEM offer better sensitivity and native 3.3V compatibility. Below is a data-dense comparison of common modules you will encounter on the bench.

Table 1: Hall Effect Current Sensor IC Comparison
Part Number Current Range Sensitivity Bandwidth Isolation Approx. Price
ACS712-20A (Legacy) ±20A 100 mV/A 80 kHz 2.1 kV RMS $2.50
ACS724-20AB ±20A 100 mV/A 80 kHz 4.8 kV RMS $3.80
ACS758-50B ±50A 40 mV/A 120 kHz 2.5 kV RMS $6.50
LEM HTFS 200-P ±200A 20 mV/A 50 kHz 2.5 kV RMS $18.00
ACS781-50U 0 to 50A (Uni) 39.6 mV/A 250 kHz 4.8 kV RMS $4.20

For a standard ESP32 DIY solar monitor or motor controller, the ACS724-20AB is the optimal choice. It natively supports 3.3V logic, features a low 1.5kΩ output impedance, and provides robust 4.8kV isolation (Allegro MicroSystems ACS724 Datasheet).

Wiring the ACS724 to an ESP32 DevKit V1

The sensor requires a stable supply voltage because its output is ratiometric. If VCC sags, your zero-offset shifts, ruining your math. Power it directly from the ESP32's 3V3 pin, ensuring your USB cable or onboard regulator can supply at least 500mA.

Table 2: ESP32 to ACS724-20AB Wiring Map
ACS724 Pin ESP32 Pin Notes
VCC 3V3 Supply range: 3.0V to 5.5V. Keep it at 3.3V for ESP32 ADC safety.
GND GND Must share a common ground with the ESP32 for the analog signal reference.
OUT GPIO 34 ADC1_CH6. Do not use ADC2 (GPIO 25-27) if WiFi is active.
IP+ / IP- Load Circuit Primary current path. Polarity matters for bidirectional sign (+/-).
Callout Tip: The Filter Capacitor
Always solder a 10nF X7R ceramic capacitor between the OUT pin and GND on your breakout board. This creates a low-pass filter with the sensor’s internal 1.5kΩ output resistance, yielding a cutoff frequency of ~10.6 kHz. This strips high-frequency switching noise from PWM motor drives before it reaches the ESP32's ADC.

The Math: Converting ADC Raw Counts to Amperes

The output of a bidirectional hall effect sensor is an analog voltage centered at exactly half of the supply voltage (VCC / 2). For a 3.3V supply, the zero-current offset is 1.65V. The ESP32 features a 12-bit ADC, meaning it maps the 0V–3.3V range to integer counts between 0 and 4095.

Step 1: Convert Raw ADC to Voltage

V_out = (ADC_raw / 4095.0) * 3.3

Step 2: Convert Voltage to Current

I = (V_out - V_offset) / Sensitivity

Worked Numeric Example

Assume you are using the ACS724-20AB. The datasheet specifies a sensitivity of 100 mV/A (0.1 V/A). Your VCC is exactly 3.3V, so V_offset is 1.65V. You poll the ESP32 and get an ADC_raw reading of 2666.

  • Voltage: (2666 / 4095.0) * 3.3 = 2.149V
  • Current: (2.149 - 1.65) / 0.1 = 0.499 / 0.1 = 4.99 Amps

Here is the complete, copy-pasteable Arduino-framework C++ code to implement this math, including an oversampling routine to stabilize the ESP32's ADC readings.

// ESP32 Hall Effect Current Sensor (ACS724-20AB)
const int SENSOR_PIN = 34;      // ADC1_CH6
const float VCC = 3.3;          // Measured VCC at the sensor
const float SENSITIVITY = 0.1;  // 100mV/A for ACS724-20AB
const int ADC_RESOLUTION = 4095.0;
const int SAMPLES = 64;         // Oversampling to reduce noise

float zeroOffsetVoltage;

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);     // Force 12-bit resolution
  
  // Calibrate Zero Offset at Startup (Ensure load is OFF!)
  long rawSum = 0;
  for(int i = 0; i < 1000; i++) {
    rawSum += analogRead(SENSOR_PIN);
    delayMicroseconds(500);
  }
  float zeroRaw = rawSum / 1000.0;
  zeroOffsetVoltage = (zeroRaw / ADC_RESOLUTION) * VCC;
  Serial.printf("Calibrated Zero Offset: %.3fV\n", zeroOffsetVoltage);
}

void loop() {
  long rawSum = 0;
  for(int i = 0; i < SAMPLES; i++) {
    rawSum += analogRead(SENSOR_PIN);
  }
  float avgRaw = rawSum / (float)SAMPLES;
  
  float vOut = (avgRaw / ADC_RESOLUTION) * VCC;
  float current = (vOut - zeroOffsetVoltage) / SENSITIVITY;
  
  Serial.printf("Raw: %4.0f | Voltage: %5.3fV | Current: %5.2f A\n", avgRaw, vOut, current);
  delay(250);
}

Interference, Calibration, and AC/DC Edge Cases

Hall effect sensors are incredibly useful, but they are not immune to physics. Understanding interference and microcontroller-specific ADC quirks is what separates a working prototype from a reliable deployment.

The ESP32 ADC Non-Linearity Trap

The ESP32’s internal ADC is notoriously non-linear at the voltage rails. According to Espressif's official ADC documentation, the ADC physically saturates around 3.1V (raw count ~3850) and exhibits a high noise floor below 0.15V.

For a bidirectional sensor centered at 1.65V, you are safely in the linear mid-band. However, if you use a unidirectional sensor (like the ACS781-50U) where 0A outputs near 0.6V and high current pushes toward 3.3V, your high-end readings will compress and become inaccurate. If you must measure unidirectional currents near the 3.3V rail, use an external I2C ADC like the ADS1115 rather than the ESP32's internal pins.

Magnetic Interference and Offset Drift

Because these sensors rely on magnetic fields, placing the breakout board within 2 inches of a transformer, a large inductor, or a permanent magnet motor will induce a false reading. The magnetic flux from external sources will bias the Hall element, shifting your zero-offset. Always mount the sensor away from high-flux components and use twisted-pair wiring for the load current to cancel out external loop areas.

Furthermore, the zero-offset drifts slightly with temperature (typically ±10mV over a -40°C to 85°C range). For precision applications, implement a software re-calibration routine that triggers when the system detects the load is physically switched off (e.g., via a relay feedback pin), updating the zeroOffsetVoltage variable dynamically.

Measuring AC Current and Calculating RMS

If you are measuring AC mains or a PWM-driven AC waveform, a simple analogRead() will just give you the instantaneous current at that exact microsecond. To get a useful Amperage value, you must calculate the Root Mean Square (RMS).

To do this accurately on a 50Hz or 60Hz line, you must sample at least twice the frequency (Nyquist theorem), but practically, you should sample at 1kHz to 2kHz. Accumulate the squared current values over one full AC cycle (20ms for 50Hz), average them, and take the square root:

I_rms = √( (1/N) * Σ(I_instantaneous²) )

Do not attempt to measure AC current by simply reading the peak voltage and dividing by √2; this only works for perfect sine waves and will yield massive errors on non-linear loads like switching power supplies or dimmed LED drivers. True RMS sampling via the math above is mandatory for accurate AC energy monitoring. For high-voltage AC applications, ensure your physical wiring respects creepage and clearance distances, and remember that while the sensor IC provides galvanic isolation, the PCB traces on cheap breakout boards often do not maintain the required physical air gaps for mains voltage safety.