The objective of this project is to create a traffic light following these steps:
Connecting wires
To carry out the assembly, you can connect:
LEDs :
the terminal (+) of green LED to pin D18 of the ESP32 board
the yellow LED (+) terminal to pin D5 of the ESP32 board
the red LED (+) terminal to pin D2 of the ESP32 board
the terminal (-) of each LED has GND of the ESP32 board
For display LCD:
the SCL pin to pin D22 of the ESP32 board
the SDA pin to the D21 pin of the ESP32 board
the VCC pin to 5v of energy
the GND to GND pin of the ESP32 board
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); void setup(){ lcd.init(); pinMode(2,OUTPUT); // For Red LED pinMode(5,OUTPUT); // For Yellow LED pinMode(18,OUTPUT); // For Green LED } void loop(){ lcd.backlight(); lcd.clear(); digitalWrite(2,HIGH); //the red LED lights up digitalWrite(18,LOW); digitalWrite(5,LOW); lcd.setCursor(0, 0); lcd.print("STOP"); // Display the word 'STOP' on the LCD display delay(3000); lcd.clear(); digitalWrite(2,LOW); digitalWrite(18,HIGH); //the green LED lights up digitalWrite(5,LOW); lcd.print("Traversez"); //Display the word 'Traversez'(cross) on the LCD display delay(3000); lcd.clear(); digitalWrite(2,LOW); digitalWrite(18,LOW); digitalWrite(5,HIGH); // the yellow LED lights up lcd.print("Traversez vite"); //Display the word 'traversez vite (cross quickly) on the LCD display delay(1000); } |