Controlling a Relay Module with ESP32 via a Web Server

Engineering illustration: Controlling a Relay Module with ESP32 via a Web Server

This project combines two ideas we covered separately before — an ESP32 web server and relay control — into one application that controls a high-voltage device via a web browser from any device on the same network.

Components needed

An ESP32 board, a relay module (single or multi-channel), a separate power supply for the relay's control circuit, and the device to be controlled.

Wiring it up

The relay module's IN1 input pin connects to GPIO26 on the ESP32 (any other suitable GPIO pin can be used), with the relay's control circuit powered separately. Since the example uses a normally-open relay configuration, the control logic is inverted: a LOW signal allows current to flow, while a HIGH signal stops it.

How it works

The code creates an HTTP server that allows remote relay control through a simple browser interface; the basic example toggles a lamp on and off automatically every 10 seconds, and the code can be extended to control several relay channels together by defining their count and each one's GPIO pin.

Very important safety note: working with AC voltage carries serious injury risks; if you aren't familiar with handling this kind of current, get help from a specialist. Always disconnect power during programming and wiring. As a safer way to experiment, it's recommended to use 12V DC power supplies with compatible relay modules instead of working directly with household mains voltage.

You can find ESP32 boards and relay modules at Juthour Tech.

Leave your comment

*
*
Only registered users can leave comments.