Blink LEDs & Programmable Timing Patterns
Master digital GPIO output, current-limiting resistor math, and non-blocking LED blink patterns on the Arduino Uno R3.
Kick off your embedded electronics journey by driving external LEDs from Arduino Uno digital pins. You will calculate safe series resistance using Ohm's Law, wire a clean breadboard circuit, and write non-blocking timing code for rhythmic indicators and sequence patterns.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerPowered directly from the Arduino Uno USB 5V rail. Each LED anode connects through a 220Ω quarter-watt current-limiting resistor so forward current stays around 13–15mA (assuming 2.0V LED forward drop), safeguarding the ATmega328P I/O drivers. 220Ω series resistors cap forward current near 13.6mA, well below the ATmega328P 40mA absolute pin limit.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 (ATmega328P) | 5V logic microcontroller board with USB-B cable | 1 | $8.00 |
| 5mm Standard LEDs (Red & Green/Blue) | Vf ≈ 2.0V–3.0V, 20mA max continuous current | 2 | $0.20 |
| 220Ω Carbon Film Resistors (1/4W) | ±5% tolerance current-limiting series resistors | 2 | $0.10 |
| Half-Size Solderless Breadboard | 400 tie-points with dual power rails | 1 | $2.00 |
| Male-to-Male Jumper Wires | 22 AWG solid-core breadboard leads | 4 | $0.50 |
Electrical & System Architecture
Digital pins D8 and D9 drive two 5mm LEDs through dedicated 220Ω series resistors, with both LED cathodes tied to the shared breadboard GND rail returning to Arduino GND.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling 5mm Red & Cyan LEDs + 220Ω Resistors acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Inspect LED Polarity & Resistor Color Bands
Verify LED anode/cathode orientation and confirm each resistor reads 220Ω (Red-Red-Brown-Gold).
- Locate the longer leg (anode +) and shorter flat-edge leg (cathode -) on both 5mm LEDs.
- Check resistor color bands or verify 220Ω with a digital multimeter.
- Confirm the Arduino Uno is disconnected from USB before wiring.
Seat LEDs & Resistors on the Breadboard
Place both LEDs across separate breadboard rows and bridge each anode through a 220Ω resistor.
- Insert LED 1 cathode into the negative blue GND rail and anode into row 10.
- Bridge a 220Ω resistor from row 10 to row 14; repeat for LED 2 on rows 18–22.
- Wire Arduino D8 to row 14, D9 to row 22, and Arduino GND to the breadboard GND rail.
Continuity & Short-Circuit Safety Audit
Confirm no direct 5V-to-GND bridge exists and that resistor legs sit in distinct electrically isolated rows.
- Trace from D8 → 220Ω resistor → LED 1 anode → LED 1 cathode → GND.
- Trace from D9 → 220Ω resistor → LED 2 anode → LED 2 cathode → GND.
- Plug in the USB cable and confirm the Arduino ON indicator lights steadily.
Upload Non-Blocking Dual-LED Firmware
Select Arduino Uno and the correct COM port in Arduino IDE, then flash the timing sketch.
- Open Arduino IDE and choose Tools → Board → Arduino Uno.
- Paste the production sketch below and click Upload.
- Open Serial Monitor at 115200 baud to observe live state transitions.
Verify Cadence & Run Pattern Experiments
Observe alternating blinks and experiment with interval modulation for strobe or Fibonacci rhythms.
- Confirm LED 1 and LED 2 alternate cleanly every 400 milliseconds.
- Watch Serial Monitor log each state toggle with exact timestamp.
- Modify BLINK_INTERVAL_MS to 100ms or 1000ms and re-upload to verify timing precision.
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: 5mm Red & Cyan LEDs + 220Ω Resistors Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for 5mm Red & Cyan LEDs + 220Ω Resistors before running the full project firmware.
// Diagnostic: Built-in & External Pin D8 Verification
const uint8_t TEST_LED = 8;
void setup() {
pinMode(TEST_LED, OUTPUT);
Serial.begin(115200);
}
void loop() {
digitalWrite(TEST_LED, HIGH);
Serial.println("D8 -> HIGH (5V)");
delay(500);
digitalWrite(TEST_LED, LOW);
Serial.println("D8 -> LOW (0V)");
delay(500);
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 1: Non-Blocking Dual LED Pattern Controller
* Board: Arduino Uno R3 | Pins: D8 (LED1), D9 (LED2)
*/
const uint8_t LED_A = 8;
const uint8_t LED_B = 9;
const unsigned long BLINK_INTERVAL_MS = 400;
unsigned long lastToggleMs = 0;
bool phaseA = true;
void setup() {
pinMode(LED_A, OUTPUT);
pinMode(LED_B, OUTPUT);
Serial.begin(115200);
Serial.println(F("Dual LED Pattern Controller Ready"));
}
void loop() {
unsigned long now = millis();
if (now - lastToggleMs >= BLINK_INTERVAL_MS) {
lastToggleMs = now;
phaseA = !phaseA;
digitalWrite(LED_A, phaseA ? HIGH : LOW);
digitalWrite(LED_B, phaseA ? LOW : HIGH);
Serial.print(F("t="));
Serial.print(now);
Serial.print(F("ms | LED_A="));
Serial.print(phaseA ? F("ON") : F("OFF"));
Serial.print(F(" | LED_B="));
Serial.println(phaseA ? F("OFF") : F("ON"));
}
}Firmware Architecture Explanation:
- Uses unsigned long subtraction (now - lastToggleMs) so millis() rollover after 49.7 days never glitches.
- Drives complementary HIGH/LOW levels on D8 and D9 to create clean alternating status signaling.
- Prints timestamped state updates over 115200 baud Serial for hardware debugging.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| phaseA = true | D8=HIGH, D9=LOW | First half-cycle | LED 1 ON, LED 2 OFF |
| phaseA = false | D8=LOW, D9=HIGH | Second half-cycle | LED 1 OFF, LED 2 ON |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| LED never illuminates | Reversed LED polarity (anode/cathode swapped) | Verify longer lead goes toward resistor/D8 and flat rim toward GND | Rotate the LED 180 degrees in the breadboard. |
| LED glows extremely dim | Wrong resistor value (e.g., 10kΩ or 100kΩ installed instead of 220Ω) | Measure resistor with DMM or check color bands | Replace with a 220Ω–330Ω resistor. |
| Upload fails with stk500_recv error | Incorrect COM port or board selection in IDE | Inspect Tools → Port and Device Manager | Select Arduino Uno and the active USB-Serial COM port. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Program LED 1 to blink in Fibonacci counts (1, 1, 2, 3, 5, 8) separated by a 1.5-second pause.
Gradually shorten the blink interval from 500ms down to 40ms, then reset smoothly.
Iterate integers 2–30 over Serial and flash the green LED only when the number is prime.