Skip to main content

Step 2: Wire the hardware

Wiring diagram: ESP32 GPIO 21/22 to INA219 SDA/SCL, load in series with INA219 Vin+ / Vin-, relay signal on GPIO 26, load power line running through the relay contacts.

Make four connections:

FromToPurpose
ESP32 GPIO 21INA219 SDAI2C data
ESP32 GPIO 22INA219 SCLI2C clock
ESP32 GPIO 26Relay signalRelay control
Load positive leadINA219 Vin+ and Vin- in seriesCurrent measurement path

Power the INA219 from the ESP32's 3V3 pin. Power the relay module from 5V. Share a common ground across all three.

This build was prototyped on a veroboard. The load is powered from an old phone charger (100-240V, 60Hz, 0.3A input; 5V, 0.6A output). A cheap USB-output charger is a convenient low-voltage supply for a first prototype.

Real-world setup: ESP32 wired to the INA219 and relay module on a veroboard, with the phone charger powering the load through the relay contacts.

danger

Mains voltage is dangerous. Do not attempt this build without someone more experienced present. The author assumes no responsibility for any damage to equipment, injury, or loss. Use a low-voltage load (USB-powered bulb, USB fan, 5V LED strip) for your first prototype. Never wire a mains-voltage load through the relay contacts unless you have the training and equipment to do it safely.

The relay module used in this tutorial is active-LOW. Pulling GPIO 26 LOW closes the contact. The firmware initializes the pin HIGH before WiFi starts, so the relay stays open during boot.