#150
Raspberry Pi Pico Traffic Light Simulator (3 LEDs Sequential, GP11/GP12/GP13)
We simulate a real traffic light with red, yellow and green LEDs — the first 3-LED project of the Pico series! Green 4 sec "go", yellow 1.5 sec "ready", red 3 sec "stop" and red+yellow 1 sec "starting" (European traffic light pattern). Learn **function definition** (`def hepsini_sondur()`), **state machine logic** (sequence) and **multi-GPIO synchronization**. Very simple circuit: 3 LEDs on GP11 (Green), GP12 (Yellow), GP13 (Red), each with a 220Ω current-limiting resistor. GP11-GP12-GP13 are ad
0.0(0)

We simulate a real traffic light with red, yellow and green LEDs. Green 4 sec "go", yellow 1.5 sec "ready", red 3 sec "stop" and red+yellow 1 sec "starting". Learn function definition, state machine logic and multi-GPIO synchronization. Very simple circuit: 3 LEDs on GP11/GP12/GP13.
Video
Circuit Diagram

Source Code
1# ─────────────────────────────────────────
2# BlueGrays · bluegrays.com
3# Pico Trafik Lambasi / Traffic Light (GP11/GP12/GP13)
4# ─────────────────────────────────────────
5# TR: Kirmizi/Sari/Yesil LED'lerle gercek trafik isigi simulasyonu
6# EN: Traffic light simulation with Red/Yellow/Green LEDs
7# TR: Fonksiyon + durum makinesi + coklu GPIO senkronizasyonu
8# EN: Function + state machine + multi-GPIO synchronization
9
10from machine import Pin
11from time import sleep
12
13# ============ PIN / PIN ============
14# TR: Trafik lambasi pinleri (yan yana GP11-GP12-GP13)
15# EN: Traffic light pins (adjacent GP11-GP12-GP13)
16yesil = Pin(11, Pin.OUT) # TR: Yesil LED — GEC | EN: Green LED — GO
17sari = Pin(12, Pin.OUT) # TR: Sari LED — HAZIRLAN | EN: Yellow LED — READY
18kirmizi = Pin(13, Pin.OUT) # TR: Kirmizi LED — DUR | EN: Red LED — STOP
19
20# ============ YARDIMCI FONKSIYON / HELPER FUNCTION ============
21def hepsini_sondur():
22 """
23 TR: Tum LED'leri sondur (DRY prensibi — tekrardan kacinmak icin)
24 EN: Turn off all LEDs (DRY principle — avoid repetition)
25 """
26 yesil.value(0)
27 sari.value(0)
28 kirmizi.value(0)
29
30print("== BlueGrays · bluegrays.com ==")
31print("Trafik Lambasi / Traffic Light")
32print("Yesil: GP11 | Sari: GP12 | Kirmizi: GP13")
33
34# ============ ANA DONGU / MAIN LOOP ============
35while True:
36 # 1) YESIL — GEC (4 sn) / GREEN — GO (4 sec)
37 hepsini_sondur()
38 yesil.value(1)
39 print("[TRAFIK/TRAFFIC] YESIL / GREEN — GEC / GO")
40 sleep(4)
41
42 # 2) SARI — HAZIRLAN (1.5 sn) / YELLOW — READY (1.5 sec)
43 hepsini_sondur()
44 sari.value(1)
45 print("[TRAFIK/TRAFFIC] SARI / YELLOW — HAZIRLAN / READY")
46 sleep(1.5)
47
48 # 3) KIRMIZI — DUR (3 sn) / RED — STOP (3 sec)
49 hepsini_sondur()
50 kirmizi.value(1)
51 print("[TRAFIK/TRAFFIC] KIRMIZI / RED — DUR / STOP")
52 sleep(3)
53
54 # 4) KIRMIZI + SARI — KALKIS (1 sn) [Avrupa pattern / European pattern]
55 # TR: Kalkis hazirligi — surucu vitese takar
56 # EN: Starting phase — driver puts car in gear
57 sari.value(1)
58 print("[TRAFIK/TRAFFIC] KIRMIZI+SARI / RED+YELLOW — KALKIS / STARTING")
59 sleep(1)
60