pb pbaumgarten.com
Courses Python Reference Relay module
Login
Course
Python Reference
Topic
MicroPython
Python Reference

Relay module

Relay Module (3.3V)

Wiring — control side (ESP32 to relay):

Relay Pin Connect To
VCC 3.3V
GND GND
IN GPIO 15

Wiring — load side (motor circuit, separate power):

Relay Terminal Connection
COM One motor terminal
NO (Normally Open) 5V positive supply
Motor other terminal 5V GND (same GND as ESP32)

{: .important } Separate power circuit: The relay switches a separate 5V circuit for the motor. The motor should NOT be powered from the ESP32's 3.3V pin — motors draw too much current and will damage the board.

Logic: - relay.on() → relay energised → COM connects to NO → motor runs - relay.off() → relay de-energised → COM disconnects from NO → motor stops

Code:

from machine import Pin
import time

relay = Pin(15, Pin.OUT)
relay.off()    # Start with motor off

relay.on()     # Motor ON
time.sleep(3)
relay.off()    # Motor OFF