TINKER PiEDESIGN IN INDIA

Traffic lightTinkerPieCircuit tutorial 15 of 24 · Intermediate · 20 minutes

Control three LEDs in a sequence, with one shared resistor, to build a traffic light.

Open this circuit in TinkerPieCircuit (free, runs in your browser)

What you will learn

Parts

TinkerPie V1 board1 red, 1 yellow and 1 green LED1 resistor, 220 Ω

Steps

  1. Add the LEDs

    Add three LEDs and set their colours in the Part tab: red, yellow and green.

  2. Wire the signals

    Wire S1 to the red LED (+), S2 to yellow (+) and S3 to green (+).

  3. Share the resistor

    Join the (−) legs of all three LEDs to one end of the 220 Ω resistor. Wire the other end to GND. Only one LED is on at a time, so one resistor is enough.

  4. Write the sequence

    Red for 2 seconds, then green for 2 seconds, then yellow for 0.8 seconds, then repeat.

  5. Press Start

    Watch the lights change in order.

The code

function setup() {
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
}

function loop() {
  digitalWrite(S1, HIGH);
  delay(2000);
  digitalWrite(S1, LOW);
  digitalWrite(S3, HIGH);
  delay(2000);
  digitalWrite(S3, LOW);
  digitalWrite(S2, HIGH);
  delay(800);
  digitalWrite(S2, LOW);
}

Copy this into the Code tab. It is Arduino-style JavaScript. The real board uses the same pin names (S1, P10…) in TinkerPie Studio.

How it works

Each LED has its own pin, so the program chooses which one lights. The shared resistor protects whichever LED is on.

Challenge: Add a pedestrian button on P10. When pressed, the red light should come on sooner.

← Why LEDs need a resistor · All 24 circuit tutorials · Light alarm for a secret box →