ArduinoFirst project

Your First Arduino Project: Blinking an LED Without Frying It

Blinking an LED is the "hello world" of electronics. It's also where a surprising number of people quietly damage their first LED or their first pin, because the tutorials skip why the resistor is there. Here's the version that explains it.

Ad space

Step 0: You don't need any wiring at all to start

The Arduino Uno has an LED already soldered onto the board, wired to pin 13 and marked L. Before you touch a breadboard, upload this and confirm your board and cable actually work:

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

In the Arduino IDE this is already built in: File → Examples → 01.Basics → Blink. Select your board and port under the Tools menu, hit Upload, and the onboard LED should start blinking once per second.

Why bother with this step? If something goes wrong later, you'll know for certain the board, the cable, and the IDE are all fine — so the problem is in your wiring. Ruling things out one at a time is most of what troubleshooting actually is.

Step 1: The external LED, and the resistor question

Now the real version. You need three things: an LED, a resistor, and two jumper wires.

An Arduino output pin puts out 5V. An ordinary red LED only needs somewhere around 2V across it to light, and wants roughly 20mA of current through it. If you connect the LED directly across 5V with nothing to limit the current, it will try to draw far more than 20mA — because an LED, unlike a resistor, doesn't limit current on its own. It just conducts harder as voltage rises, until something gives.

That "something" is either the LED (it burns out, sometimes instantly, sometimes over minutes) or the Arduino's output pin.

What size resistor?

The arithmetic is Ohm's law, and it's genuinely this simple:

150Ω is the minimum you'd want. In practice almost every starter kit hands you 220Ω or 330Ω, and either is fine — they run the LED a little dimmer and a little safer. If you're not sure, use 330Ω. A slightly dim LED tells you nothing is wrong; a dead one tells you too late.

Different colour LEDs have different forward voltages. Blue, white and green LEDs typically need more (often around 3V) than red. If you swap a red LED for a blue one and it looks dim, that's why — not a fault. Check the specific LED's datasheet if you want to be exact.

Step 2: Wiring it

  1. Arduino pin 9 → one leg of the resistor.
  2. Other leg of the resistor → the LED's long leg (the anode, positive side).
  3. LED's short leg (the cathode, negative side) → Arduino GND.

The resistor can go on either side of the LED — before it or after it — and the circuit behaves identically. Current is the same everywhere in a simple series loop. Put it wherever it's tidier on your breadboard.

Telling an LED's legs apart: the longer leg is the positive side (anode). If the legs have been trimmed, look at the plastic rim — there's a flat spot on the negative (cathode) side.

The code

const int LED_PIN = 9;

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);   // LED on
  delay(500);
  digitalWrite(LED_PIN, LOW);    // LED off
  delay(500);
}
Ad space

The four mistakes that actually cause problems

1. No resistor

Covered above, and it's the big one. An Arduino Uno pin can supply a maximum of around 40mA before you're outside the chip's absolute ratings, with roughly 20mA being the sensible working figure. A resistor-less LED sails past that.

2. LED in backwards

An LED is a diode — it only conducts one way. Backwards, it simply won't light. The good news: at 5V this doesn't damage anything, so if your LED is dark, flipping it around is the first thing to try. Not lighting up is far more often a backwards LED than a broken one.

3. Wiring to the 5V pin instead of a numbered pin

The 5V pin is always on — it's a power supply, not something your code controls. Wire your LED there and it'll light constantly and ignore your sketch entirely. It needs to go to a numbered digital pin (0–13) for digitalWrite() to do anything.

4. Trying to drive lots of LEDs from lots of pins

One LED per pin is fine. But the chip also has a limit on total current across all pins at once, not just per pin — so a row of eight or ten LEDs all lit simultaneously can exceed what the chip can safely deliver even if each individual pin is within spec. Once you're past a few LEDs, that's the point to look at a transistor, a driver IC, or a shift register rather than brute-forcing it from the pins.

Where to go next

Swap digitalWrite() for analogWrite(LED_PIN, 128) on a PWM-capable pin (marked with a ~ on the board) and you can fade the LED instead of just switching it. That one change is the doorway to motor speed control, servo positioning, and dimming — all the same underlying idea.

If you're moving to a Raspberry Pi for a project instead, note the rules change: Pi GPIO pins are 3.3V, not 5V, and are considerably less tolerant of mistakes. The GPIO mistakes guide covers the differences, and PinTinker will plan the pin assignments for you.

Gear that helps

An Arduino Uno starter kit with an assortment of resistors and LEDs covers everything in this article and a lot more besides. A basic multimeter is the other thing worth having early — being able to check a resistor's actual value takes the guesswork out of colour codes.