tutorialspinouttools
Sensors · ESP32-C3

ACS712 on OLED: Current Sensor

Free ESP32 & Arduino tutorial · wiring, code & parts · gokul.builds

Overview & Wiring

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.

Circuit Diagram

ACS712 on OLED: Current Sensor wiring diagram for ESP32-C3

Parts You Need

ESP32-C3 SuperMiniBuy →
0.96" SSD1306 OLEDBuy →

Source Code (Arduino / ESP32)

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);

#define ACS 0                 // OUT (via divider) on GPIO0 (ADC)
const float SENSITIVITY = 0.185; // V per A: 5A=0.185, 20A=0.100, 30A=0.066
const float DIVIDER = 0.667;     // your OUT->GPIO0 divider ratio
float vZero = 2.5 * 0.667;       // updated at startup

float readNodeVolts() {
  long sum = 0;
  for (int i = 0; i < 32; i++) sum += analogReadMilliVolts(ACS);
  return (sum / 32.0) / 1000.0;                // volts at the ADC pin
}

void setup() {
  Serial.begin(115200);
  Wire.begin(4, 5);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  delay(300);
  vZero = readNodeVolts();                      // zero-current baseline (load OFF)
}

void loop() {
  float vNode = readNodeVolts();
  float vOut = vNode / DIVIDER;                 // undo divider -> real sensor V
  float vZeroReal = vZero / DIVIDER;
  float amps = (vOut - vZeroReal) / SENSITIVITY;

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("ACS712 Current");
  display.setTextSize(3);
  display.setCursor(0, 22);
  display.printf("%.2f", amps);
  display.setTextSize(1);
  display.setCursor(0, 54); display.print("amps");
  display.display();

  Serial.printf("Current: %.2f A\n", amps);
  delay(300);
}
Browse all tutorials ESP32-C3 pinout Calculators