GAMERIFTRobotics & Coding Shop kits
HomeKitsFor schoolsAboutGAMERIFT Store ↗
Beginner Kit · Lesson 02 of 12

Traffic Robot

One LED is a light. Three LEDs with the right timing is a system, and systems are where engineering begins.

Unlock your missions

Enter the access code from the card inside your Beginner Kit (or from your GAMERIFT order email).

Don't have a kit yet? Get the Beginner Kit. Lost your code? Contact us.

LICENSED TO , PERSONAL USE · © GAMERIFT

BRIEF Run an intersection

Somewhere in your town, a box of electronics is doing this exact job right now, and thousands of people trust it with their lives every hour. Today you build that box: green, amber, red, in the right order, with the right timing. Get the order wrong and, as real cities have discovered after software updates gone bad, you get chaos.

Time: 45 minutes · Difficulty: 1/5 · Builds on: Lesson 01

KIT What you need

Concept · The ground rail

The long blue-striped row down the edge of your breadboard is a rail: every hole in it is connected. Wire the R3's GND pin to the rail once, and all three LEDs can share it. One wire in, three loops out, this is how real circuit boards stay tidy.

Concept · Sequence is meaning

Code runs top to bottom, one line at a time, and the order is the behaviour. Green-then-amber-then-red is a safe intersection; red-then-green-then-amber is an accident report. When your program misbehaves, read it in order, line by line, as if you were the chip.

BUILD Wire it

USB unplugged first. Each LED gets the same loop you built in Lesson 01, just on its own pin:

FromToWhy
R3 GNDBlue (−) railOne shared ground for everything
Pin 13Resistor → red LED long legRed's signal wire
Pin 12Resistor → yellow LED long legAmber's signal wire
Pin 11Resistor → green LED long legGreen's signal wire
Each LED short legBlue (−) railThree loops, one ground

Space the LEDs a few rows apart so legs never touch. Stack them red on top, amber middle, green below, like the real thing.

CODE Program it

// GAMERIFT Beginner Kit, Lesson 02: Traffic Robot

const int red   = 13;
const int amber = 12;
const int green = 11;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(amber, OUTPUT);
  pinMode(green, OUTPUT);
}

void loop() {
  digitalWrite(green, HIGH);   // GO
  delay(4000);
  digitalWrite(green, LOW);

  digitalWrite(amber, HIGH);   // get ready to stop…
  delay(1500);
  digitalWrite(amber, LOW);

  digitalWrite(red, HIGH);     // STOP
  delay(4000);
  digitalWrite(red, LOW);      // …and loop() starts over at green
}

Upload it. You should see a calm, correct intersection. Watch a full cycle and check: does red ever overlap green? (It shouldn't, and now you know why each colour is switched LOW before the next goes HIGH.)

BREAK IT Now break it on purpose

  1. Delete the line digitalWrite(green, LOW); and upload. Green and amber now burn together, one missing line, one broken promise to drivers. Put it back.
  2. Reorder the blocks so red comes straight after green. Legal code, dangerous intersection. The computer never checks your meaning, only your spelling.
  3. Set every delay to 300. A traffic light for a city of hummingbirds. Timing is design.

REMIX Make it yours

LOG IT Show and tell

Film one full cycle of your remix for your mission log. Stuck? Photo of the wiring to the contact form and a human will find the loose leg.

Next · Lesson 03: Press to Play

So far your circuit only talks. Next lesson it learns to listen: you wire your first button and build a machine that reacts the moment you press.