040 - MicroPython TechNotes: Relay

Introduction

In this article, I will discussed about the RELAY with ESP32 using MicroPython.

Pinout

  1. G – for the the ground.
  2. V – for the supply voltage.
  3. S – for the control signal pin.

Bill Of Materials

  1. ESP32 development board.
  2. Gorillacell ESP32 shield.
  3. 3-pin F-F Dupont wires.
  4. Gorillacell relay module.

Hardware Instruction

  1. Connect relay G pin to ESP32 GND pin.
  2. Connect relay V pin to ESP32 5V pin.
  3. Connect relay S pin to ESP32 GPIO 23 pin.

Software Instruction

  1. Copy example program in the source code section.
  2. Please feel to modify according to your needs.

Video Demonstration

Call To Action

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:

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin
 5
 6relay = Pin(23, Pin.OUT)
 7
 8
 9# ******************************************************************
10# The following should be explored using the REPL:
11# ******************************************************************
12# # 1. To activate the relay, set signal pin to logic 1
13# relay.value(1)
14
15# # 2. To deactivate the relay, set signal pin to logic 0
16# relay.value(0)

2. Example # 2, simple application:

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin
 5from time import ticks_ms
 6
 7relay = Pin(23, Pin.OUT)
 8sw = Pin(0, Pin.IN)
 9
10isActive = False
11start = ticks_ms()
12
13while True:
14    if ticks_ms()-start>=300:
15        if sw.value()==0:
16            isActive = not isActive
17            relay.value(isActive)
18        start=ticks_ms()

References And Credits

  1. Purchase your Gorillacell ESP32 development kit at: https://gorillacell.kr


Posts in this series



No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.