Zach Christensen
arduino journey
P02First LightSession 2✓ Working

External LED

First wired circuit, and Ohm's Law by actually using it.

Carried forward fromP01 Blink
Running
Notebook

Worked out by hand before anything got wired. Why that matters.

The sketch

02_External_LED.inocomments stripped
const uint8_t PIN_LED = 9;void setup() {  pinMode(PIN_LED, OUTPUT);  Serial.begin(9600);  Serial.println("P02 - external LED ready");}void loop() {  digitalWrite(PIN_LED, HIGH);  Serial.println("ON");  delay(500);  digitalWrite(PIN_LED, LOW);  Serial.println("OFF");  delay(500);}

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:

StepWorkingResult
Vr5 - 32 V across the resistor
R2 / 0.010200 Ω ideal, 220 Ω is what I own
Check2 / 2209.1 mA, inside 5 to 20 mA
Check2 × 0.009118 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