Traffic lights
This project is simple and easy to build, even for beginners. I used a ready-made traffic light module, but you can also use three separate LEDs. My traffic light already had the resistors built in, but if you use three LEDs, I recommend adding three 220Ω resistors.
Required components:
-
Arduino board (I used a Nano, but any Arduino-compatible microcontroller will work)
-
LEDs: red, yellow, green (or a pre-assembled traffic light module, like the one I used)
-
220Ω resistor (if you use external LEDs)
-
Jumper wires
-
Breadboard (optional, but recommended)
Connections:
-
Red LED → pin 8 → through a 220Ω resistor → GND
-
Yellow LED → pin 9 → through a 220Ω resistor → GND
-
Green LED → pin 10 → through a 220Ω resistor → GND
The LED anode (long leg) connects to the Arduino pin, and the cathode (short leg) connects to GND.
Code:
// Definim pinii LED-urilor
const int ledRosu = 8;
const int ledGalben = 9;
const int ledVerde = 10;
// Timpul fiecărui LED (în milisecunde)
const int timpRosu = 3000;
const int timpGalben = 1000;
const int timpVerde = 3000;
void setup() {
pinMode(ledRosu, OUTPUT);
pinMode(ledGalben, OUTPUT);
pinMode(ledVerde, OUTPUT);
}
void loop() {
// Verde aprins
digitalWrite(ledVerde, HIGH);
digitalWrite(ledGalben, LOW);
digitalWrite(ledRosu, LOW);
delay(timpVerde);
// Galben aprins
digitalWrite(ledVerde, LOW);
digitalWrite(ledGalben, HIGH);
digitalWrite(ledRosu, LOW);
delay(timpGalben);
// Roșu aprins
digitalWrite(ledVerde, LOW);
digitalWrite(ledGalben, LOW);
digitalWrite(ledRosu, HIGH);
delay(timpRosu);
}
