Green LED on D9 through a 220 Ω resistor to ground. On for 500ms, off for 500ms, printing to Serial as it goes. The code barely changed from Blink. Everything here was in the wiring.
Sizing the resistor
Supply is 5 V and a green LED drops about 3 V just by conducting, so 2 V is left for the resistor. Targeting 10 mA, from the 5 to 20 mA range an indicator LED is happy in:
| Step | Working | Result |
|---|---|---|
| Vr | 5 - 3 | 2 V across the resistor |
| R | 2 / 0.010 | 200 Ω ideal, 220 Ω is what I own |
| Check | 2 / 220 | 9.1 mA, inside 5 to 20 mA |
| Check | 2 × 0.0091 | 18 mW, resistor is rated 250 mW |
Two checks, not one. Current is about the LED and the pin. Power is about the resistor, which cooks if you ignore it.
What I learned
- LEDs are polarized. Long leg is the anode and goes to +, short leg is the cathode and goes to ground. Backwards just means no light, not damage
- Every LED needs a current-limiting resistor. A diode does nothing to limit its own current, so 5V straight across it kills the LED or the pin or both
- Resistor before or after the LED makes no difference. Same loop, same current
- Both legs in the same numbered row shorts the LED out. Rows a to e are one node, so the legs have to straddle the middle channel
- Serial Monitor baud has to match
Serial.begin(9600)or you get garbage - Opening the Serial Monitor resets the board
- Power off before wiring. Habit for later when a slip costs a servo
- Picked D9 because it does PWM, so this same wiring gets reused for the fade sketch