LAB 003
Multiple Outputs: A Traffic Signal
Build three copies of the LED circuit and sequence them with explicit instructions.
01
What you will build
Three individually driven LEDs on D8, D9 and D10 in a traffic-light-like sequence.
Why it matters
Repetition in wiring and code motivates loops and arrays after a working simple build.
What you will learn
- multiple independent output pins
- state progression and timing
- repetition, loops and arrays as optional improvements
02
Parts List
- Arduino Uno R3 is a 5 V ATmega328P microcontroller board for direct control of sensors, switches and small driver circuits using a single uploaded program. UNO-format board with USB-B socket, barrel connector, ATmega328P and digital/analog header labels. The canonical Uno R3 is separate from the generic compatible-board record. Identify pins from the board labels/pinout rather than a diagram for a newer Uno generation.
- An 830-contact solderless breadboard joins inserted leads through hidden spring strips so circuits can be rebuilt without solder. Full-size rectangular board, center channel, numbered five-hole terminal groups and side power rails. Counted contact holes are not component units.
- An assortment of discrete indicator LEDs provides several visible colors for status and display experiments. Loose two-lead lens packages of different tints; transparent lenses can emit several different colors.
- A mixed resistance assortment supplies values for current limiting, biasing and divider experiments. Groups of axial two-lead resistors; use labeled storage and measure uncertain parts out of circuit.
- Male-to-male jumper leads make removable point-to-point connections for low-current prototype signals. Pins at both ends; count individual leads rather than ribbon groups. Check intact insulation and snug contacts before use.
- A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. Rectangular USB-A plug at one end and square USB-B plug at the other; standalone purchase length is recorded as ten feet. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
03
Assembly
Disconnect USB before changing breadboard wiring; check connections before reconnecting.
Use one 220–330 Ω resistor in series with each ordinary LED. Never connect 5V directly to GND.
- 01
Disconnect USB. Build three separate LED branches using the Lab 2 method, with one verified 220–330 Ω series resistor for each LED. You may arrange the components yourself, but do not place both resistor legs in one connected group.
- 02
Connect D8 through a resistor to LED 1, D9 through a resistor to LED 2 and D10 through a resistor to LED 3. Connect all three LED cathodes to Uno GND; if you share a ground rail, confirm that its used section actually connects to GND.
- 03
Trace each branch from its digital pin to GND. Check all three LED polarities, resistor values, breadboard groups and pin assignments before reconnecting USB. The red, amber and green names in the code describe roles; actual LED colors may differ.
- 04
Select the core program Three explicit phases, then Save, Build and Upload. Identify the D8, D9 and D10 phases: about one second, half a second and one second respectively.
- 05
Change one phase delay, upload again and check that only the intended phase duration changes.
| From | To | Purpose / notes |
|---|---|---|
| Uno D8 | LED 1 series resistor 220–330 Ω | Drive output with current limitingPut the resistor in series, never across 5V and GND. |
| LED 1 series resistor | LED 1 anode (long leg) | Feed LED in forward directionResistor may instead go on the cathode side if it stays in series. |
| LED 1 cathode (short leg/flat side) | Uno GND | Complete the circuitLED must not be connected directly across 5V and GND. |
| Uno D9 | LED 2 series resistor 220–330 Ω | Drive output with current limitingPut the resistor in series, never across 5V and GND. |
| LED 2 series resistor | LED 2 anode (long leg) | Feed LED in forward directionResistor may instead go on the cathode side if it stays in series. |
| LED 2 cathode (short leg/flat side) | Uno GND | Complete the circuitLED must not be connected directly across 5V and GND. |
| Uno D10 | LED 3 series resistor 220–330 Ω | Drive output with current limitingPut the resistor in series, never across 5V and GND. |
| LED 3 series resistor | LED 3 anode (long leg) | Feed LED in forward directionResistor may instead go on the cathode side if it stays in series. |
| LED 3 cathode (short leg/flat side) | Uno GND | Complete the circuitLED must not be connected directly across 5V and GND. |
Predict before you run
- Which LED comes after D8, and for how long?
- What happens if two phases are given the same HIGH state?
Only one of the three LEDs is on at a time: D8, then D9, then D10.
- Observe at least two complete three-phase cycles.
- Confirm each named pin controls its expected LED.
04
Code
Arduino Uno R3
Replace src/main.cpp with one complete example. Save → Build → Upload. These labs need no external libraries.
Copy the Uno platformio.ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 9600
#include <Arduino.h>
// Labels are roles; actual LED colors may differ.
// These three names represent the traffic-light roles and the corresponding output pins.
const int redLed = 8;
const int amberLed = 9;
const int greenLed = 10;
// Each wired LED has a separate output that must be initialized.
void setup() {
pinMode(redLed, OUTPUT);
pinMode(amberLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop() {
// Phase 1: red on, amber and green off.
digitalWrite(redLed, HIGH);
digitalWrite(amberLed, LOW);
digitalWrite(greenLed, LOW);
delay(1000);
digitalWrite(redLed, LOW);
// Phase 2: red off, amber on for a shorter warning interval.
digitalWrite(amberLed, HIGH);
// This 500 ms amber phase is shorter than either 1000 ms phase.
delay(500);
digitalWrite(amberLed, LOW);
// Phase 3: green on. The following LOW turns it off before repeating.
digitalWrite(greenLed, HIGH);
delay(1000);
digitalWrite(greenLed, LOW);
}
Experiments & challenges
- Change only the middle phase duration.
- Swap the positions of two LEDs with USB disconnected, then predict which physical position lights first.
Scale it up
Optionally expand to five LED/resistor branches on D8–D12; compare explicit code, a loop and a pin array.
Challenge
Write a three-phase pattern with two LEDs illuminated briefly; explain how to avoid accidental simultaneous high states.
Advanced implementation
What to remember
- Which repeated instruction would you put in a loop?
- The repeated pattern is digitalWrite(pin, HIGH), delay(...), then digitalWrite(pin, LOW). A loop can apply that pattern to each LED pin instead of repeating it separately.
- What does an array let you change in one place?
- An array keeps the LED pin numbers together in one list. A loop can use that list for setup and switching, so changing the list changes which outputs it visits.
Learning summary
Repeated physical outputs have repeated setup and control logic; abstraction becomes useful as output count grows.
Lab 4 replaces a fixed timed sequence with behavior controlled by a human button.
Troubleshooting
No upload or no power
Check USB data cable, selected PlatformIO Uno environment and upload port; verify the power LED.
Unexpected external LED behavior
Disconnect USB, check the breadboard row, LED polarity, series resistor, GND, then compare the code pin with the wire.
Wrong phase or two lights on
Compare D8/D9/D10 wire labels with pin constants and verify all three outputs are reset LOW between phases.