
Traffic Light
Beginner20 minA real traffic light with three LEDs: red, red + yellow, green and yellow light up in the order used in Turkey, and each stage is also written to the Serial Monitor. It teaches driving several outputs in turn, timing with digitalWrite and delay, and gathering a repeated job into its own function. You can change how long each light stays on with the constants in the code. No extra library needed.

What you need
1 × Arduino Uno R3
1 × Breadboard 830 Points (MB-102)
1 × LED - Red (5mm)
1 × LED - Yellow (5mm)
1 × LED - Green (5mm)
3 × Resistor 220 Ω (1/4W)
4 × Jumper Wire - Male/Male
Wiring steps
- 1
Connect the common ground (GND)

Plug a black jumper wire into the GND pin next to pin 13 on the Arduino's digital header. Connect its other end to the breadboard's top blue (−) rail. All three LEDs' resistors will go into this rail, so they share one ground.
- Arduino GND → the top blue (−) rail (black wire)
- 2
Add the red LED and its resistor

Plug the red LED's long leg (+) into column 11 in the top half of the breadboard and its short leg (−) into column 12. Put one end of a 220 Ω resistor in column 12 and the other end in the top (−) rail. Then connect the Arduino's pin 11 to column 11 with a red jumper wire (RED_PIN 11). The resistor limits the current through the LED; without it both the LED and the Arduino's pin can be damaged.
- red LED long leg (+) → column 11, top half
- red LED short leg (−) → column 12, top half
- red LED's resistor (leg 1) → column 12, top half
- red LED's resistor (leg 2) → the top blue (−) rail
- Arduino pin 11 → column 11, top half (red wire)
- 3
Add the yellow LED and its resistor

Plug the yellow LED's long leg (+) into column 14 in the top half and its short leg (−) into column 15. Put the second 220 Ω resistor between column 15 and the top (−) rail. Connect the Arduino's pin 10 to column 14 with a yellow jumper wire (YELLOW_PIN 10).
- yellow LED long leg (+) → column 14, top half
- yellow LED short leg (−) → column 15, top half
- yellow LED's resistor (leg 1) → column 15, top half
- yellow LED's resistor (leg 2) → the top blue (−) rail
- Arduino pin 10 → column 14, top half (yellow wire)
- 4
Add the green LED and its resistor

Plug the green LED's long leg (+) into column 17 in the top half and its short leg (−) into column 18. Put the third 220 Ω resistor between column 18 and the top (−) rail. Connect the Arduino's pin 9 to column 17 with a green jumper wire (GREEN_PIN 9). That completes the circuit.
- green LED long leg (+) → column 17, top half
- green LED short leg (−) → column 18, top half
- green LED's resistor (leg 1) → column 18, top half
- green LED's resistor (leg 2) → the top blue (−) rail
- Arduino pin 9 → column 17, top half (green wire)
Arduino sketch
Download the sketch (.ino)Try it on Wokwi
// The traffic light's pins
const int RED_PIN = 11;
const int YELLOW_PIN = 10;
const int GREEN_PIN = 9;
// How long each light stays on (ms)
const unsigned long RED_TIME = 5000;
const unsigned long YELLOW_TIME = 2000;
const unsigned long GREEN_TIME = 5000;
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
Serial.begin(9600);
}
// Sets all three lights: HIGH is on
void lights(int red, int yellow, int green) {
digitalWrite(RED_PIN, red);
digitalWrite(YELLOW_PIN, yellow);
digitalWrite(GREEN_PIN, green);
}
void loop() {
// Stop: red only
lights(HIGH, LOW, LOW);
Serial.println("Red: stop");
delay(RED_TIME);
// Get ready: red and yellow together
lights(HIGH, HIGH, LOW);
Serial.println("Red + yellow: get ready");
delay(YELLOW_TIME);
// Go: green only
lights(LOW, LOW, HIGH);
Serial.println("Green: go");
delay(GREEN_TIME);
// Caution: yellow only
lights(LOW, HIGH, LOW);
Serial.println("Yellow: caution, stopping");
delay(YELLOW_TIME);
}
What the Serial Monitor shows
Red: stop Red + yellow: get ready Green: go Yellow: caution, stopping Red: stop Red + yellow: get ready
What you will see
The red LED lights for 5 seconds, then red and yellow light together for 2 seconds, then green alone for 5 seconds, and finally yellow alone for 2 seconds before the cycle starts again. If an LED never lights, first check its legs (the long one goes to the Arduino's pin) and that its resistor sits in the (−) rail.
Similar projects
Parking SensorIntermediate45 minLike the parking sensor in a car: the HC-SR04 measures the distance to whatever is in front of it, the buzzer starts beeping once something comes within 1 metre and the beeps get faster as it comes closer; below 10 cm the tone is steady. Green, yellow and red LEDs show the far, middle and near zones, and the distance is written to the Serial Monitor. It teaches timing with millis() instead of delay, so measuring, beeping and the lights run without waiting for each other, writing a function that returns a value, splitting into zones with if / else if, and turning the distance into a beep gap with map. No extra library needed.Open project
Air Quality IndicatorBeginner30 minAn indicator that shows a room's air like a traffic light: the MQ-135 sensor reacts to pollutants such as smoke, ammonia, benzene and the CO₂ that builds up from breathing; green lights while the air is clean, yellow as it starts to get stale and red when it is bad, and the Serial Monitor tells you to air the room. At start the sensor warms up and the clean-air value is measured; every reading after that is judged against it, and if the air gets even cleaner the value is updated. It teaches reading an analog sensor against its own clean-air value, reducing jitter by averaging several readings and leaving a margin at the thresholds so the LEDs do not flicker at the edge. No extra library is needed. The MQ-135 does not tell gases apart and does not give a calibrated CO₂ reading; it shows roughly how polluted the air is.Open project
Smoke and Gas AlarmIntermediate35 minAn alarm that goes off when smoke or a flammable gas (LPG, natural gas, methane) shows up in the kitchen or a room: the MQ-2 sensor's analog output is read, the clean air value is measured at start-up, and once the reading rises well above it the buzzer plays the three-beep pattern (T3) that real smoke alarms use while the red LED flashes with the beeps. The green LED blinks while warming up and stays on once the alarm is armed. It teaches reading an analog sensor against its own clean air value, using two separate thresholds so the alarm does not flicker at the edge, and playing a sound pattern with millis() while still taking readings. No extra library needed. This is a learning project; it does not replace a certified smoke and gas alarm at home.Open project
In the app, tick off every wire, match the parts to your inventory and pick up where you left off.
