~60 min. Wire an external LED to a digital pin on the R4. Modify the Blink sketch to control it. Demonstrate that you can apply weeks 1-6 to a microcontroller project.
Goal: bridge from the built-in LED (which has its own internal resistor) to an external LED that needs its own current limiter; verify your week-5 resistor-sizing skill
Estimated time: 60 minutes
Prerequisites: lab 7.1 complete; lab 5.1 complete (LED current control)
Steps
Step 1: Plan the circuit (10 min)
You want an external LED to blink when the Arduino sets a pin HIGH. Pick:
- Pin: 8 (a digital-only pin; not PWM-capable, which is fine for blinking)
- LED color: red (low forward voltage; common kit color)
- Resistor: at 5 V supply (which is what the pin outputs when HIGH), with 2 V LED drop and 15 mA target: R = (5 - 2) / 0.015 = 200 Ω. Round up: 220 Ω (a standard value)
Sketch the schematic: pin 8 → 220 Ω → LED anode; LED cathode → ground
Step 2: Wire on the breadboard (15 min)
From R4 pin 8: jumper to breadboard tie-strip. From that tie-strip: through the 220 Ω resistor to another tie-strip. From that tie-strip: LED anode (long lead) to that tie-strip; LED cathode (short lead) to a different tie-strip; that tie-strip to R4's GND pin via jumper
Triple-check: the LED's anode is the longer lead and goes on the +5V (pin 8) side; the cathode goes to ground
Step 3: Modify the Blink sketch (10 min)
Open the sketch from lab 7.1. Change LED_BUILTIN to 8 in both pinMode and digitalWrite calls. The sketch becomes:
void setup() {
pinMode(8, OUTPUT);
}
void loop() {
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
}
Save as blink-pin8.ino. Upload
Step 4: Verify (10 min)
The external LED on the breadboard should blink at 1 Hz. The built-in LED should be off (since the sketch no longer drives LED_BUILTIN)
If not working:
- Is the LED polarity correct? (Long lead toward the pin)
- Is the resistor value reasonable? (220 Ω works at 5 V; 1 kΩ also works but is dimmer; 0 Ω is dangerous and damages the LED)
- Is the ground connection good? (Probe with multimeter: pin 8 should be 5 V when HIGH and 0 V when LOW)
Step 5: Add a second LED (15 min)
Wire a second LED + resistor to pin 9. Modify the sketch to blink both LEDs alternately (one on while the other off). Upload. Confirm both work
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(500);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(500);
}
Expected output
- External LED blinking on pin 8
- Second LED alternating on pin 9
- Confirmation that week 5 resistor-sizing applies to Arduino projects
Common pitfalls
- Forgetting the resistor: an LED directly on a 5 V pin will burn out quickly. Always include the current-limit resistor. The R4's pin can source up to 8 mA per pin reliably; an unlimited LED can easily exceed that
- Wrong pinMode: forgetting pinMode(8, OUTPUT) means the pin is in default INPUT mode. digitalWrite has no effect. Always set the mode in setup()
- Short between pin and ground: a wire that accidentally shorts a HIGH-driven pin to ground draws too much current and can damage the pin. Verify your breadboard before powering on
Stretch (optional)
- Wire three LEDs on three pins; cycle through them in a chase pattern (one at a time, moving left)
- Wire an RGB LED (if your kit has one) on three pins. Cycle through red, green, blue colors. Combine for white (all three on simultaneously)
- Replace one of the LEDs with the kit's buzzer (with its current-limit resistor if any). The buzzer beeps in sync with the blinking. Loud; consider time of day
Lab 7.2 v0.1. The first time your microcontroller controls external hardware that you wired yourself.