#107Beginner
ESP32 Traffic Light
Real traffic light simulation with 3 LEDs red-yellow-green. Timings close to real traffic logic: red long, yellow short, green long. Classic example of sequential GPIO control.
4.4(19)
29 completed

Real traffic light simulation with 3 LEDs red-yellow-green. Timings close to real traffic logic: red long, yellow short, green long. Classic example of sequential GPIO control.
Video
Circuit Diagram

Source Code
1const int RED = 5;
2const int YELLOW = 18;
3const int GREEN = 19;
4
5void setup() {
6 pinMode(RED, OUTPUT);
7 pinMode(YELLOW, OUTPUT);
8 pinMode(GREEN, OUTPUT);
9}
10
11void loop() {
12 // Kırmızı / Red
13 digitalWrite(RED, HIGH);
14 digitalWrite(YELLOW, LOW);
15 digitalWrite(GREEN, LOW);
16 delay(3000);
17
18 // Kırmızı + Sarı / Red + Yellow
19 digitalWrite(YELLOW, HIGH);
20 delay(800);
21
22 // Yeşil / Green
23 digitalWrite(RED, LOW);
24 digitalWrite(YELLOW, LOW);
25 digitalWrite(GREEN, HIGH);
26 delay(3000);
27
28 // Sarı / Yellow
29 digitalWrite(GREEN, LOW);
30 digitalWrite(YELLOW, HIGH);
31 delay(800);
32 digitalWrite(YELLOW, LOW);
33}