LED Traffic Light Module

Draft. This tutorial has not been checked against the physical product yet. Confirm wiring, pin assignments and voltage limits against the product documentation before building it.
DifficultyBeginner
CategoryOutputs
Supported boardsArduino Uno R3 and compatible ATmega328P boards
Time needed45 minutes
PrerequisitesGetting Started with Arduino Uno
Tested boardNot yet verified
Tested onNot yet verified
Arduino IDE versionNot yet verified
LibraryNot yet verified

What it does

The traffic light module puts a red, a yellow and a green LED on one small board with a shared ground connection, so three separate outputs can be wired with four jumper wires instead of six wires and three loose resistors.

It is the clearest way to learn the step that every output project depends on: deciding which pin is on, which is off, and for how long. A traffic light is a good first example because the rules are already familiar, and because a mistake is obvious rather than subtle. If two lamps are lit at once, you can see it.

The same pattern drives status indicators on a machine, a battery-level display, or any panel that has to show one state at a time.

Before you begin

Required parts and tools

  • An Arduino Uno or compatible board, already set up.
  • One LED traffic light module.
  • Four female-to-male jumper wires, or four male-to-male wires and a breadboard.
  • A USB data cable.

The board Siratek sells

The module on the Siratek product page has four pins, marked R, Y, G and GND on the silkscreen, and a small surface-mount resistor beside each LED.

Two things follow, and they make this simpler than many tutorials suggest.

  • The three LEDs share one ground connection. A signal pin set HIGH lights its lamp, and LOW turns it off. There is no VCC pin and nothing to connect to 5V.
  • The current-limiting resistors are already on the board. Do not add your own. Extra resistance in series will only make the lamps dim.

Boards print the labels in different orders, and the module can be inserted either way round. Match the printed label to the wire rather than counting positions in the row.

If you have a different module from elsewhere with a fifth VCC pin, it is the common-anode kind: the anodes are tied to VCC, and every HIGH and LOW in the sketch below swaps over.

Safety and electrical notes

  • An Uno I/O pin is rated for about 20 mA. The sketch below lights one lamp at a time, which keeps the board well inside that.
  • If you modify the sketch to light several lamps together, remember the limit applies to the total drawn through the ground return as well as to each pin.
  • Make every connection with the USB cable unplugged, then plug in.
  • GND is not optional. Without it the circuit has no return path and the lamps behave unpredictably rather than simply staying off.

Pin reference

Pin or label Connect to Purpose Notes
GND Uno GND Common ground return Required, connect this one first
R Uno D8 Red lamp HIGH lights it on a common-ground module
Y Uno D9 Yellow lamp Sometimes labelled A for amber
G Uno D10 Green lamp
VCC nothing Not present on this module A board that has one is the common-anode kind

Pins 8, 9 and 10 are ordinary digital pins with nothing special about them. They are chosen here because they are grouped together on the header and keep clear of D0 and D1, which carry the USB serial traffic.

Wiring steps

Traffic light module wired to an Arduino Uno, R to pin 8, Y to pin 9, G to pin 10 and GND to ground
Four wires and nothing else. The resistors beside each LED are already fitted.
  1. Unplug the USB cable from the Uno.
  2. Connect the module’s GND pin to any GND pin on the Uno.
  3. Connect R to digital pin 8.
  4. Connect Y to digital pin 9.
  5. Connect G to digital pin 10.
  6. Check each wire against the printed label on the module, following it with a finger from the module pin to the Uno pin. A wire one position out is the single most common fault here.
  7. Plug the USB cable back in.

Nothing should light up yet. The pins are still in their default state, and whatever sketch was previously on the board is now running.

Software and libraries

No library is required. pinMode(), digitalWrite() and delay() are all part of the Arduino core, and the Serial Monitor output uses nothing extra.

Minimal working example

The helper function turns every lamp off before turning one on. That single habit is what guarantees you can never show two colours at once, however the timing is later changed.

// Siratek: LED traffic light module.
// Cycles green, yellow and red, and reports each phase over USB.

const int redPin = 8;
const int yellowPin = 9;
const int greenPin = 10;

// Phase durations in milliseconds. These are the numbers to change.
const unsigned long greenTime = 5000;
const unsigned long yellowTime = 2000;
const unsigned long redTime = 5000;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);

  Serial.begin(9600);
  Serial.println("Siratek: traffic light starting.");
}

// Clears all three lamps, lights one, then holds it.
void showOnly(int pin, const char *name, unsigned long holdFor) {
  digitalWrite(redPin, LOW);
  digitalWrite(yellowPin, LOW);
  digitalWrite(greenPin, LOW);

  digitalWrite(pin, HIGH);
  Serial.println(name);
  delay(holdFor);
}

void loop() {
  showOnly(greenPin, "green", greenTime);
  showOnly(yellowPin, "yellow", yellowTime);
  showOnly(redPin, "red", redTime);
}

Two things you may need to change. If your wiring differs, edit redPin, yellowPin and greenPin to match. If you have a five-pin common-anode module, swap the LOW and HIGH values inside showOnly().

Expected result

One lamp at a time, repeating: green for five seconds, yellow for two, red for five.

With the Serial Monitor open at 9600 baud you should see the phase names appear in step with the lamps:

Siratek: traffic light starting.
green
yellow
red
green

The serial output is the useful part when something looks wrong. If the names are cycling at the right pace but the lamps are not following, the fault is in the wiring rather than the sketch.

Troubleshooting

Symptom Likely cause Check or fix
Nothing lights at all GND not connected Connect the module GND to an Uno GND pin
All three lit, going dark one at a time Common-anode module driven as common-ground Connect VCC to 5V and swap HIGH and LOW in showOnly()
Lamps in the wrong order Signal wires crossed Follow each wire from the module label to the pin number
One colour never lights That wire, or that LED Move the working green wire onto the dead pin to tell which
Lamps very dim Module has no onboard resistors and is on a weak supply, or board is 3.3 V Check for the three resistors, and confirm the board is a 5 V Uno
One lamp glowed brightly once, then nothing No series resistor, LED destroyed Fit 220-330 ohm resistors before replacing the module
Lamps flicker or cut out Loose jumper or breadboard contact Reseat every wire with the cable unplugged
Serial shows phases, lamps dead Wired to the wrong pins Confirm 8, 9, 10 against the sketch
Upload fails after wiring Something on D0 or D1 Move it to another pin
Two lamps lit together showOnly() edited, or a short between pins Restore the three LOW lines, then check for touching wires

Next steps

  • Easier first: Getting Started with Arduino Uno, if the upload or the Serial Monitor gave you trouble here.
  • Related product: the tactile push button, which turns this fixed cycle into one that responds to a pedestrian.
  • Next project: add the passive buzzer and sound a short tone during the crossing phase.

Two worthwhile extensions once it runs. Many countries show red and amber together before green; adding that phase means lighting two lamps at once, so work out the current first. And delay() stops the whole program while it waits, so a button pressed during a phase is ignored. Rewriting the cycle around millis() is the standard fix, and it is what the push button tutorial builds towards.

Sources and attribution

All text, wiring guidance and code in this tutorial are original Siratek work.

  • Arduino core reference for pinMode(), digitalWrite() and delay().
  • Arduino Uno R3 documentation and ATmega328P datasheet for the per-pin current limit.

Module pin labelling varies between suppliers, so the two wiring styles above are described from the labels on the board rather than copied from any manufacturer’s document. No third-party tutorial text, diagrams, photographs or code has been reproduced here.

Product used in this tutorial: LED Traffic Light Module
Shop
Sidebar
0 Wishlist
0 Cart