006 - MicroPython TechNotes: Traffic Light LED Module
Introduction
In this article, we will learn on how to use the Traffic Light LED module. It is a small model or miniature of the traffic light.
Pinout
- G – for the ground.
- V – for the supply voltage.
- Green – for the control signals for green LED.
- Yellow – for the control signals for yellow LED.
- Red – for the control signals for red LED.
Bill Of Materials
- ESP32 development board.
- Gorilla Cell ESP32 shield (optional)
- 5-pin dupont jumper wires.
- Traffic Light LED module.
Hardware Instruction
- Attach the ESP32 on top of the ESP32 shield making sure that the pins are properly aligned and both the USB port are on the same side.
- Attach the dupont jumper wires to Traffic Light LED module by following a color coding which is:
- black – for the ground.
- red – for the VCC.
- yellow and following colors – for the control signal.
- Attach the other side of the dupont jumper wires on ESP32 shield by matching the colors of the dupont wires to the pin headers of ESP32 shield pin headers.
- Power the ESP32 shield with the USB type-C cable.
- Power ON the shield by sliding the slide switch to ON / BATT.
- Connect the ESP32 to computer by connecting the micro USB cable.
Software Instruction
- Open the Thonny Python IDE. If you don’t have this installed, be sure to watch the article tutorial # 1.
- Press the “Stop” button to let the Thonny Python IDE to connect to ESP32.
- Create a new Python file by clicking the “New” button.
- Copy and paste the provided source code below to your Thonny.
- Press “Run the current script” to execute the code.
- Enjoy and feel free to modify it according to your liking.
Video Demonstration
Call To Action
For any concern, write your message in the comment section.
You might also like to support my journey on Youtube by Subscribing. Click this to Subscribe to TechToTinker.
Thank you and have a good days ahead.
See you,
– George Bantique | tech.to.tinker@gmail.com
Source Code
1. Traffic Light LED: Example # 1, simple turn ON and OFF:
1from machine import Pin
2from time import sleep
3
4g = Pin(23, Pin.OUT)
5y = Pin(25, Pin.OUT)
6r = Pin(26, Pin.OUT)
7
8# The following code should be
9# tested on the REPL.
10g.on() # Turn ON green LED.
11g.off() # Turn OFF green LED.
12
13r.value(1) # Turn ON red LED.
14r.value(0) # Turn OFF red LED.
15
16y.value(True) # Turn ON yellow LED.
17y.value(False) # Turn OFF yellow LED.
2. Traffic Light LED: Example #2, running LED:
1from machine import Pin
2from time import sleep
3
4g = Pin(23, Pin.OUT)
5y = Pin(25, Pin.OUT)
6r = Pin(26, Pin.OUT)
7led = [r, y, g]
8
9while True:
10 for x in range(3):
11 led[x].on()
12 sleep(0.3)
13 led[x].off()
3. Traffic Light LED: Example #3, single traffic light:
1from machine import Pin
2from time import sleep
3
4g = Pin(23, Pin.OUT)
5y = Pin(25, Pin.OUT)
6r = Pin(26, Pin.OUT)
7
8traffic_state = ['SOLID_GRN',
9 'BLINK_GRN',
10 'SOLID_RED',
11 'SOLID_ORN']
12
13while True:
14 for x in traffic_state:
15 if x == 'SOLID_GRN':
16 g.on()
17 sleep(6)
18 g.off()
19
20 if x == 'BLINK_GRN':
21 for i in range(4):
22 g.on()
23 sleep(0.3)
24 g.off()
25 sleep(0.3)
26
27 if x == 'SOLID_RED':
28 r.on()
29 sleep(7)
30 r.off()
31
32 if x == 'SOLID_ORN':
33 y.on()
34 sleep(1)
35 y.off()
References And Credits
Posts in this series
- 049 - MicroPython TechNotes: MP3 Player
- 048 - MicroPython TechNotes: Analog Touch Sensor
- 047 - MicroPython TechNotes: E108 GPS
- 046 - MicroPython TechNotes: RF433 Transceivers
- 045 - MicroPython TechNotes: Infrared Transmitter
- 044 - MicroPython TechNotes: Infrared Receiver
- 043 - MicroPython TechNotes: ESP12E WiFi | External WiFi module
- 042 - MicroPython TechNotes: JDY-32 | Bluetooth Low Energy BLE
- 041 - MicroPython TechNotes: Bluetooth HC-06
- 040 - MicroPython TechNotes: Relay
- 039 - MicroPython TechNotes: Electromagnet
- 038 - MicroPython TechNotes: Buzzer
- 037 - MicroPython TechNotes: Servo Motor
- 036 - MicroPython TechNotes: Stepper Motor
- 035 - MicroPython TechNotes: Dual Motor Driver
- 034 - MicroPython TechNotes: DC Motors | Gear Motor and Fan Motor
- 033 - MicroPython TechNotes: TCS34725 RGB Color Sensor
- 032 - MicroPython TechNotes: BMP280 Sensor
- 031 - MicroPython TechNotes: TOF Distance Sensor
- 030 - MicroPython TechNotes: DS3231 RTC
- 029 - MicroPython TechNotes: HC-SR04 Ultrasonic Sensor
- 028 - MicroPython TechNotes: DHT11 Temperature and Humidity Sensor
- 027 - MicroPython TechNotes: Rotary Encoder
- 026 - MicroPython TechNotes: Light Dependent Resistor (LDR)
- 025 - MicroPython TechNotes: Joystick
- 024 - MicroPython TechNotes: Slider Switch
- 023 - MicroPython TechNotes: Continuous Rotation Potentiometer
- 022 - MicroPython TechNotes: Potentiometer | Reading an Analog Input
- 021 - MicroPython TechNotes: Color Touch Sensor
- 020 - MicroPython TechNotes: Touch Sensor
- 019 - MicroPython TechNotes: Switch Module
- 018 - MicroPython TechNotes: Button | Reading an Input
- 017 - MicroPython TechNotes: LASER Module
- 016 - MicroPython TechNotes: RGB LED Matrix
- 015 - MicroPython TechNotes: Neopixel 16
- 014 - MicroPython TechNotes: 8x8 Dot Matrix Display (I2C)
- 013 - MicroPython TechNotes: 8x16 Dot Matrix Display (SPI)
- 012 - MicroPython TechNotes: 8x8 Dot Matrix Display (SPI)
- 011 - MicroPython TechNotes: 1.3 OLED Display
- 010 - MicroPython TechNotes: 0.96 OLED Display
- 009 - MicroPython TechNotes: 7 Segment Display
- 008 - MicroPython TechNotes: 16x2 LCD
- 007 - MicroPython TechNotes: RGB LED
- 005 - MicroPython TechNotes: Gorilla Cell LED | MicroPython Hello World
- 004 - MicroPython TechNotes: Gorilla Cell I/O Devices
- 003 - MicroPython TechNotes: Gorillacell ESP32 Shield
- 002 - MicroPython TechNotes: Introduction for Gorillacell ESP32 Dev Kit
- 001 - MicroPython TechNotes: Get Started with MicroPython
- 000 - MicroPython TechNotes: Unboxing Gorillacell ESP32 Development Kit
No comments yet!