Source: https://mokxi.com/learn/blink-an-led-arduino
Updated: 2026-09-27

Learn

# Blink an LED with an Arduino Uno

Written by the Mokxi team, updated September 27, 2026

Sign up free or see every lesson

- 192 parts on the bench
- 25 boards running now
- 1.00x real time, on every board

Click to open it in the editor

The built-in blink program, plus an LED and a 220 ohm resistor wired to pin 13.

This is the first program almost everyone runs on an Arduino, and it is worth understanding completely rather than just typing it in. The circuit above is the Uno's built-in `blink` sketch: pin 13 is set as an output, driven high for half a second, then low for half a second, forever. Pin 13 is worth knowing by name, because the Uno has an LED already soldered next to the USB socket and wired to it, which is why `LED_BUILTIN` is simply the number 13. The external LED and resistor wired into the circuit above do the same job on the breadboard, so you can watch both LEDs blink together and see that they are, electrically, the same signal.

Nothing here is simulated for looks. The sketch really does run on a modeled ATmega328P, and `delay()` really does put the chip to sleep between the two timer ticks it waits for rather than spinning the CPU, which is why this costs the simulator almost nothing while it waits, the same as it costs a real Uno almost nothing. Press Run above and the on-board LED and the breadboard LED blink in lock step, once a second.

Download the lesson plan (PDF)

## Wiring the LED and picking the resistor

An LED has a long leg, the anode, and a short leg, the cathode, and it only conducts one way around: current runs from anode to cathode, never the other way. In the circuit above, pin 13 feeds the resistor, the resistor feeds the LED's anode, and the LED's cathode goes to GND. Get the LED backwards and no current flows at all: it does not light dimly, it does not light briefly, it simply stays dark, because a diode wired against its own polarity blocks the circuit as completely as an open switch.

The resistor is not optional and it is not there by convention. An LED's forward voltage sits close to a fixed value, about 2 volts for a common red or green LED, and once the circuit reaches that voltage the LED will pull as much current as anything else in the loop lets through it. Wired straight across 5 volts with nothing else in the way, an LED asks for far more current than a Uno's pin or the LED itself is built to survive. The resistor's job is to be the thing that actually decides the current, since the LED will not do it for you.

The math is Ohm's law with the LED's own drop subtracted first: (5 V minus 2 V) divided by the resistor. At 220 ohms that is 3 V over 220 ohms, about 13.6 milliamps, which is bright and comfortably inside what a small indicator LED is rated for. A 330 ohm resistor gives roughly 9 mA, a touch dimmer; a 100 ohm resistor gives roughly 30 mA, brighter and closer to the edge of what a small LED or an ATmega328P pin should be asked to supply continuously. 220 ohms is the value almost every kit ships because it lands solidly in the middle of that range, not because any other value is wrong.

## The code, line by line

The whole sketch is eight lines outside its comments. `pinMode(LED_BUILTIN, OUTPUT)` in `setup()` runs once and tells the ATmega328P's I/O port to drive that pin rather than read it; skip this line and `digitalWrite()` has no effect, because a pin left as an input cannot source or sink the current an LED needs. `loop()` then runs forever: `digitalWrite(LED_BUILTIN, HIGH)` sets the pin to 5 volts, `delay(500)` waits five hundred milliseconds while doing nothing else, `digitalWrite(LED_BUILTIN, LOW)` sets it back to 0 volts, and the second `delay(500)` waits again before the loop repeats.

firmware/examples/blink (the exact program running above)

## Common mistakes

The LED wired backwards is the single most common reason a first circuit stays dark, and it is worth checking first because it looks identical to every other wiring mistake from the outside: nothing lights, and there is no error to read. Flip the LED around and try again before touching anything else.

The second most common mistake is skipping the resistor, on the reasoning that the LED lights fine without one on the bench for a second or two. It usually does, briefly, which is exactly the trap: a real LED run without current limiting degrades or fails after repeated use, and a real ATmega328P pin is only rated for about 40 mA. Mokxi's parts have no destructive failure mode, on purpose, so a resistor-free circuit here just reports a current a real one could not survive: a safe way to see the mistake without losing anything, but not a reason to build it that way on the bench.

The third is wiring the LED and resistor to the wrong rail: to 5 V instead of GND, or to a pin that was never set to `OUTPUT`. And the fourth, specific to a breadboard, is a leg landing one row off from where the rest of the circuit is strung, which reads as a complete, correct-looking circuit that simply is not connected. Mokxi's breadboard rows are exactly the real 0.1 inch grid, so a part pushed a row too far behaves exactly as it would on the bench: nothing, with no hint why.

## Moving from the simulator to a real breadboard

Everything in the circuit above transfers to a real Uno unchanged: the same pin, the same resistor value, the same two-leg LED. The one habit worth building now, before real parts are involved, is checking a circuit's polarity and connections with the power off, in your head or on the screen, before ever applying power. On a real bench that check is what a burned-out LED or a warm resistor teaches the hard way; here it costs nothing to get wrong, which is exactly why it is worth practicing the right way regardless.

If you own an Uno already, the fastest way to see this is to build the same three-part circuit on your own breadboard, upload the sketch above from the Arduino IDE, and compare it side by side with the simulator running the identical code. They should look and behave the same, because Mokxi's Uno model runs the same C++ on a modeled ATmega328P rather than approximating the result.

## Questions

Can I blink the LED on a different pin?

Yes. Any digital pin can be set as an OUTPUT and driven with digitalWrite; pin 13 is only special because the Uno has its own LED wired to it already. Change the pin number in both pinMode and digitalWrite and rewire the external LED to match.

What if my LED still does not light?

Check the LED's orientation first (the longer leg is the anode, toward the resistor and the pin), then check the resistor is actually in the current path rather than off to one side, and then check the ground leg reaches the Uno's GND and not another rail.

Can I blink two LEDs at once, at different rates?

Not with delay(), which stops the whole sketch while it waits. The page on blinking without delay shows the millis()-based pattern that lets two lamps run at two rates from one loop.

Do I need the resistor if the LED feels dim without it?

A dim LED needs a smaller resistor, not no resistor. Removing it entirely removes the only thing limiting the current, which is a real risk to the LED and the pin on actual hardware even though nothing here can be destroyed by trying it.

Does the resistor go before or after the LED?

Electrically it makes no difference in a simple series loop: a resistor limits the same current wherever it sits in the loop. Most diagrams put it between the pin and the LED's anode purely because that is easier to read, not because the other order is wrong.

Related

## Keep going

Ohm's Law, in a Circuit You Can Run Picking a Resistor for an LED Arduino Projects for Beginners, Each One Running Arduino LED Not Lighting Up or Dim: What to Check Arduino Compile Errors Explained, With the Fixes The Arduino Uno simulator Blink two LEDs at once, without delay() The same first program on an ESP32-C3 Open a blank circuit in the editor

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building Open the editor
