Overview
An LED is a diode: it conducts in one direction only and needs its current limited by a resistor. Get both of those right and it will last for years.
You will need
- Arduino Uno R3
- 5 mm LED
- 330 Ω resistor (orange-orange-brown)
- Breadboard and two jumper wires
Wiring
| Uno pin | Connects to | Notes |
|---|---|---|
| 7 | 330 Ω resistor, then LED anode (long leg) | Pin HIGH = LED on (active-high). |
| GND | LED cathode (short leg, flat edge on the rim) |
Polarity
The anode (+) is the longer leg. The cathode (−) is the shorter leg, and the plastic rim is flattened on that side. Reversed, the LED simply stays dark; it is not damaged at 5 V.
Active-high and active-low
Wired as above, writing HIGH turns the LED on.
You can also wire the anode to 5V and the cathode (through the resistor) to the pin; then
LOW turns it on. Both are fine, but your code must match the wiring.
The sketch
const int LED_PIN = 7;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(300);
digitalWrite(LED_PIN, LOW);
delay(700);
}How the code works
Naming the pin with a const int means you change the wiring in one place. With a
330 Ω resistor and a red LED (about 2 V forward voltage) the current is (5 − 2) ÷ 330 ≈ 9 mA,
comfortably bright and well within the pin's limit.
What you should observe
- A short 0.3 s flash every second.
- No light at all: check the LED's direction first, then that the resistor and LED share a strip.