What it is: The ACS712 measures DC (or AC) current using the Hall effect, with full electrical isolation between the measured circuit and your ESP32. Modules come in 5A (185 mV/A), 20A (100 mV/A) and 30A (66 mV/A) versions.
How it works: It outputs a voltage centred at half its 5V supply (≈2.5V at zero current) that moves up or down with current. Current = (Vout − Vzero) / sensitivity. Because Vout can swing across the full 0–5V range, you MUST divide it down before the 3.3V ESP32 ADC.
Wiring:
ACS712 OUT -> voltage divider -> GPIO0 (see note)
ACS712 VCC -> 5V
ACS712 GND -> GND
Load current passes through the two screw terminals (in series with your load).
VOLTAGE WARNING: put a divider on OUT (e.g. 10k from OUT to GPIO0 and 20k from GPIO0 to GND gives a 0.667 ratio) so the 0–5V output maps to 0–3.3V. Set DIVIDER in code to match.
OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5
Libraries: only "Adafruit SSD1306" and "Adafruit GFX Library".
On screen / Serial: current in amps. The sketch measures the zero-current offset at startup, so keep the load OFF during the first second.
Gotchas: The ACS712 is noisy near zero (±0.1A jitter is normal); the sketch averages samples. SENSITIVITY must match your module (185/100/66 mV per A). Never connect mains without proper insulation and knowledge — stick to low-voltage DC loads for learning.