science tinker

Pedestrian crossing: Arduino project with wiring and code

Breadboard wiring for Pedestrian crossing, as drawn in the simulator.

Car lights on pins 12 (red), 11 (yellow) and 10 (green); a push button on pin 2 (to GND). Cars normally have green. When someone presses the button: yellow for 1 s, red for 4 s, then green again. Cars must always get at least 3 s of green between crossings: if the button is pressed too early, remember it and start the crossing when the 3 s are up.

  • Arduino Uno
  • Advanced level
  • 8 parts
  • Free, in your browser

You will learn: State machines, remembering a request in a variable, and millis() for timing without blocking.

Project 22 of 62 in the project gallery.

Parts you need

PartHow manyWhat it does in this project
Arduino Uno1Runs your sketch and powers the circuit.
LED (light-emitting diode)3The car lights: red on pin 12, yellow on pin 11 and green on pin 10.
Push button1The pedestrian's request button. Pressing it asks the lights to change so people can cross.
220 Ω resistor3Limits the current so the part it protects is not damaged.
Breadboard and jumper wires1Hold the parts and join them without soldering.

How to wire it

Put the parts on the breadboard, join the board's 5V and GND pins to the breadboard's power rails, then make these connections:

PartConnection
Push buttonpin 2 → button → GND (use INPUT_PULLUP)
LEDpin 10 → LED → GND (220 Ω)
LEDpin 11 → LED → GND (220 Ω)
LEDpin 12 → LED → GND (220 Ω)

In the Studio, the 💡 guide rings show where each wire goes, and the ✔ Check button tells you which connection is missing.

Starter code

Start from this sketch and write the missing lines. The comments say what each part has to do.

const int RED = 12;
const int YELLOW = 11;
const int GREEN = 10;
const int BUTTON = 2;
bool waiting = false;     // someone pressed the button
long greenSince = 0;      // when the cars got green (ms)

void lights(int r, int y, int g) {
  digitalWrite(RED, r);
  digitalWrite(YELLOW, y);
  digitalWrite(GREEN, g);
}

void setup() {
  pinMode(RED, OUTPUT);
  pinMode(YELLOW, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
  lights(LOW, LOW, HIGH);   // cars: green
}

void loop() {
  // 1. if the button is pressed (LOW), set waiting = true
  // 2. if waiting and the cars have had green for 3000 ms:
  //    yellow 1 s, red 4 s, green again, then greenSince = millis() and waiting = false
}

Build it step by step

  1. Open the project. Press Build it in the Studio. The parts are already in the tray.
  2. Place and wire the parts. Follow the wiring table above, or switch on the guide rings.
  3. Write the code. Complete the starter sketch in the Code panel, in text or with blocks.
  4. Run it. Press ▶ Run and use the part's slider, button or switch to test it. The Serial Monitor shows what your sketch prints.
  5. Check it. Press ✔ Check: the simulator tests the circuit and the code and tells you exactly what to fix.

Questions students ask

What does the Pedestrian crossing project do?

Car lights on pins 12 (red), 11 (yellow) and 10 (green); a push button on pin 2 (to GND). Cars normally have green. When someone presses the button: yellow for 1 s, red for 4 s, then green again. Cars must always get at least 3 s of green between crossings: if the button is pressed too early, remember it and start the crossing when the 3 s are up.

What parts do I need for the Pedestrian crossing project?

An Arduino Uno, 3 × LED, push button, 3 × 220 Ω resistor, a breadboard and jumper wires.

How do I wire the Pedestrian crossing project?

Push button: pin 2 → button → GND (use INPUT_PULLUP); LED: pin 10 → LED → GND (220 Ω); LED: pin 11 → LED → GND (220 Ω); LED: pin 12 → LED → GND (220 Ω). Power comes from the board's 5V (or 3.3V) and GND pins along the breadboard rails.

What will I learn from the Pedestrian crossing project?

State machines, remembering a request in a variable, and millis() for timing without blocking.

Can I build this without real hardware?

Yes. The project runs in the free Science Tinker microcontroller simulator in your browser: place the parts, wire them, write the sketch and press Run. The ✔ Check button tests your circuit and code and tells you what to fix. Nothing to install and no account needed.

Where is the finished code?

The page gives the starter sketch so that you write the important lines yourself. If you are stuck, the 💡 Solution button in the Studio shows a complete, working sketch that you can run and study.

More advanced projects

Components in this project

Know someone who would use this?

It’s free for every learner. Send it to your class, team or club.

Updated · Free, no sign-up ·