TK03DIGITALbeginner

Traffic Light

Red, yellow and green LEDs, each with its own 1 kΩ resistor and its own pin, sharing one GND: three digital outputs, and the first sketch that has to remember what it is doing.

Comes in this kit — not sold separately

Specifications

TypeThree-LED output block, active high, one pin per light
LEDsRed, yellow and green, 0805 surface-mount, stacked red on top
Resistors1 kΩ each, one per LED, between its cathode and GND. Printed 1001
CurrentAbout 3.1 mA for red and yellow and 2.3 mA for green from a 5 V pin; about 1.4 and 0.6 mA from 3.3 V. Worked out from the datasheets, not measured
Pins to wire4 of the 6: GND, RED, YELLOW and GREEN. The two NC pins are connected to nothing on the board
Header6-pin right-angle male, 2.54 mm pitch: GND, NC, NC, RED, YELLOW, GREEN, with GND on the square pad
SupplyNone of its own. Each signal pin powers its own LED, so brightness follows your board's logic voltage
Board22.4 × 30.4 mm, two 4.8 mm mounting holes 16 mm apart
In the box1 × TK03 block. It also ships inside the TinkerBlock kits

What it is

Three LEDs, three resistors and a header. The LEDs are small surface-mount parts stacked red, yellow and green beside a traffic light drawn in the silkscreen. Each has its own 1 kΩ resistor and its own pin, and the three share nothing but GND.

It is active high. Set a colour's pin HIGH and that light comes on, LOW and it goes out. The back of the board says so: each GPIO controls one light, HIGH turns on, LOW turns off.

The TK03 at an angle: a black board with a gold border, three small LEDs stacked red, yellow and green near the top beside a traffic light drawn in outline, lonely binary printed up the left edge, two large mounting holes, three small black resistors in a row, and a right-angle header whose six pins point out past the bottom edge.
The TK03. The header is right-angled, so the board lies flat.

Nothing on the board stops two lights showing at once, the way a real signal's controller would. The sequence lives entirely in your sketch, which is what makes this block the natural first lesson in a program that remembers what it is doing.

Three lights, three currents

There is no supply pin: each signal pin powers its own LED. The green takes about 2.7 V before it conducts and the red and yellow about 1.9 V, so the green gets less of what is left:

Your boardPin voltageRedYellowGreen
Arduino Uno5 Vabout 3.1 mAabout 3.1 mAabout 2.3 mA
ESP32, ESP32-S3, Pico3.3 Vabout 1.4 mAabout 1.4 mAabout 0.6 mA

All of it is well within what any of these boards' pins may supply. The currents are worked out from the three LED datasheets, which give ranges, not measured on a board.

Which pin is which

LEDs up, header at the bottom, reading left to right:

GNDto your board's GNDthe square pad: count from here
NCnothingnot connected on the board
NCnothingnot connected on the board
REDto a digital pinHIGH lights red
YELLOWto a digital pinHIGH lights yellow
GREENto a digital pinHIGH lights green

The back prints TK03 TRAFFIC LIGHT and what the pins do instead of their names. Turned over, the square pad is on the right, and it is still GND.

Wiring, in four lines

  1. GND to your board's GND.
  2. RED to D9 on an Uno, GPIO 25 on an ESP32, GPIO 4 on an ESP32-S3, or GP13 on a Pico.
  3. YELLOW to D10, GPIO 26, GPIO 5 or GP14.
  4. GREEN to D11, GPIO 27, GPIO 6 on the S3, or GP15.

Leave both NC pins unconnected. No resistor to add, no library to install.

Example

// GPIO numbers. Uno: 9, 10, 11. ESP32: 25, 26, 27. ESP32-S3: 4, 5, 6.
// Pico: 13, 14, 15.
const int RED_PIN = 4;
const int YELLOW_PIN = 5;
const int GREEN_PIN = 6;

// Set all three at once, so no step can leave a light on by mistake.
void show(bool red, bool yellow, bool green) {
  digitalWrite(RED_PIN, red ? HIGH : LOW);
  digitalWrite(YELLOW_PIN, yellow ? HIGH : LOW);
  digitalWrite(GREEN_PIN, green ? HIGH : LOW);
}

void setup() {
  pinMode(RED_PIN, OUTPUT);
  pinMode(YELLOW_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
}

void loop() {
  show(HIGH, LOW, LOW);   // red
  delay(5000);
  show(LOW, LOW, HIGH);   // green
  delay(5000);
  show(LOW, HIGH, LOW);   // yellow
  delay(2000);
}

This is the plain red, green, yellow cycle many countries use. The UK, among others, shows red and yellow together before green; the handbook adds it as one row of a table.

The Traffic Light running on an Arduino Uno

Where to start

The handbook below is eight short articles, each with a working figure. The lamp test is the wiring in four wires and a sketch that proves it.

If you only read one, read a sketch that remembers. The example above waits for seconds at a time and notices nothing while it does; that article rewrites it so it never waits.

And if the green looks dim on your ESP32, why the green is different works out why that is normal.

When it doesn’t work

One light never comes on.
Two lights working proves GND and the block, so it is that colour's own wire or its own line of code. The number in the sketch is the GPIO number printed beside the pin on your board, not its position along the header, and every pin needs its own pinMode. Run the lamp test sketch: it names each colour as it lights it.
Why is the green dimmer on my ESP32?
The green LED takes about 2.7 V before it conducts, against about 1.9 V for the red and yellow, so a 3.3 V pin leaves it much less for its resistor: about 0.6 mA against 1.4 mA. It is normal. From a 5 V board the difference is much smaller, and the green's datasheet rates it bright at small currents.
Do I need to add resistors?
No. Each LED already has its own 1 kΩ resistor on the board, between the LED and GND, and it keeps the current well inside what any common board's pin may supply.
Two lights are on at once.
Nothing on the board prevents it: each pin lights its own LED whenever it is HIGH. The sketch left one on. Set all three pins in every step, even the ones that do not change, and it cannot happen.
What are the two NC pins for?
Nothing on this board. They are in no net at all. They keep the header's first positions the same as every other TinkerBlock block's, and this block needs only four of its six pins.
The sequence stops responding to anything else.
A sketch built from delay() is deaf while it waits, and a traffic light waits for seconds. Keep the current phase in a variable and compare millis() with the time it started instead. The handbook below rewrites the sequence that way.

The traffic light handbook

8 articles · about 40 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

What is on the board

2 articles

Six pins of which four do something, three LEDs each with its own resistor, and nothing on the board that stops all three lighting at once.

Lighting it

2 articles

Four wires and a sketch that lights each colour in turn to prove the wiring, then why the green draws less current than the other two and still looks as bright.

The sequence

2 articles

Red, green, yellow, written the obvious way with delay(), and then again as a sketch that remembers which light is showing and checks the clock instead of waiting.

A second mode, and when it will not light

2 articles

A flashing yellow night mode switched from the serial monitor, which only works because the sketch never waits, and the short list of reasons a light stays dark.

Lessons using TK03

Each one is a working build, not a snippet.

Edit this page — content/modules/traffic-light.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Traffic Light

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum