040 – MicroPython TechNotes: Relay

In this article, I will discussed about the RELAY with ESP32 using MicroPython.
Relay inactive state: signal value is logic 0.
COM pin is connected to normally-closed NC pin.


Relay active state: signal value is logic 1.
COM pin is connected to normally-open NO pin.

PINOUT:
- G – for the the ground.
- V – for the supply voltage.
- S – for the control signal pin.
BILL OF MATERIALS:
- ESP32 development board.
- Gorillacell ESP32 shield.
- 3-pin F-F Dupont wires.
- Gorillacell relay module.
HARDWARE INSTRUCTION:
- Connect relay G pin to ESP32 GND pin.
- Connect relay V pin to ESP32 5V pin.
- Connect relay S pin to ESP32 GPIO 23 pin.
SOFTWARE INSTRUCTION:
- Copy example program in the source code section.
- Please feel to modify according to your needs.
VIDEO DEMONSTRATION:
If you have any question regarding this video, please write your message in the comment section.
You might also like to support me on my Youtube channel by Subscribing. Click this to Subscribe to TechToTinker.
Hope you find it useful. Thank you.
Regards,
– George Bantique | tech.to.tinker@gmail.com
SOURCE CODE:
1. Example # 1, exploring the basics:
# More details can be found in TechToTinker.blogspot.com
# George Bantique | tech.to.tinker@gmail.com
from machine import Pin
relay = Pin(23, Pin.OUT)
# ******************************************************************
# The following should be explored using the REPL:
# ******************************************************************
# # 1. To activate the relay, set signal pin to logic 1
# relay.value(1)
# # 2. To deactivate the relay, set signal pin to logic 0
# relay.value(0)
2. Example # 2, simple application:
# More details can be found in TechToTinker.blogspot.com
# George Bantique | tech.to.tinker@gmail.com
from machine import Pin
from time import ticks_ms
relay = Pin(23, Pin.OUT)
sw = Pin(0, Pin.IN)
isActive = False
start = ticks_ms()
while True:
if ticks_ms()-start>=300:
if sw.value()==0:
isActive = not isActive
relay.value(isActive)
start=ticks_ms()
REFERENCES AND CREDITS:
1. Purchase your Gorillacell ESP32 development kit at: