Your first Arduino project: blink an LED on a breadboard (and why it needs a resistor)
TUREFF• •0
Blinking an LED is the "hello world" of electronics. It looks trivial, but it teaches the shape of every Arduino program, how a breadboard is wired inside, and the single most important habit in the hobby: limiting current with a resistor.
What you need
- an Arduino Uno or similar board and its USB cable
- a solderless breadboard
- one LED (any colour)
- one resistor, somewhere in the few-hundred-ohm range (more on choosing it below)
- two jumper wires
How a breadboard is wired inside
A breadboard lets you build circuits without soldering. Under the holes are metal strips:
- In the main area, each short row of five holes is connected together. The two halves either side of the central gap are not connected to each other.
- Along the long edges there are usually power rails, marked + and -, connected along their length. On some boards the rail is split halfway; check before relying on it.
If two component legs share a row, they are connected. If they are in different rows, they are not, unless a wire joins them.
Why the LED needs a resistor
An LED does not limit its own current. Connected straight to a pin, it will draw as much as it can, which can burn out the LED and strain or damage the pin. A resistor in series sets the current.
Ohm's law gives the value: current equals voltage divided by resistance (I = V / R). The voltage across the resistor is the supply voltage minus the LED's forward voltage, which is roughly 2 V for a red LED and higher for blue or white ones (check your LED's data).
Worked example for a 5 V board and a red LED:
- voltage across the resistor: 5 V minus about 2 V = about 3 V
- a 330 ohm resistor: 3 / 330 = about 0.009 A, or roughly 9 mA
That is bright enough to see and comfortably gentle. Pin current limits differ between boards, and the newer Uno R4 boards allow much less per pin than the older R3, so look up your board's limit and pick a larger resistor if in doubt. A dimmer LED costs nothing; a damaged pin does.
Wiring it up
With the USB unplugged:
- Push the LED into the breadboard so its two legs sit in different rows. The longer leg is the positive side (anode); the flat edge on the rim marks the negative side (cathode).
- Put the resistor from the anode's row to an empty row.
- Run a jumper from that empty row to digital pin 13 (or whichever pin your sketch uses).
- Run a jumper from the cathode's row to a GND pin.
It does not matter which side of the LED the resistor goes on, as long as it is in series.
The code: setup and loop
Every Arduino sketch has two functions:
- setup() runs once when the board powers up or resets. Here you tell the board how each pin is used.
- loop() runs over and over, forever, after setup has finished.
The program, written as plain lines:
void setup() { pinMode(13, OUTPUT); }
void loop() { digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); delay(500); }
pinMode makes pin 13 an output. digitalWrite sets it HIGH (on) or LOW (off). delay waits the given number of milliseconds, so this flashes once a second.
Upload it, and the LED should blink in step with the small on-board LED, which is wired to the same pin on an Uno.
If it does not light
- Turn the LED round; it only works one way.
- Check the legs are in different rows, not both in one.
- Make sure the GND wire really goes to a GND pin.
- Confirm the pin number in the code matches the wire.
Next steps
Change the delays to make a heartbeat pattern, add a second LED on another pin with its own resistor, or try analogWrite on a pin marked with a tilde (~) to fade the LED instead of switching it.
Did your first blink work first time? Share your photos, questions and resistor maths in the comments.