Built-in project · Arduino Uno R3

Blink an LED on pin 3, on an Arduino Uno

A red LED and a 220 ohm resistor on pin 3, switched on and off every half second: the first sketch you write yourself. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $30. On Mokxi they're free.

Blink an LED on pin 3 · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

What you'll learn

  • Setting a pin as an output
  • HIGH and LOW as 5 V and 0 V
  • Timing with delay
  • Why the LED needs a resistor
  • The setup and loop structure
  • Difficulty: Beginner
  • Time: About 10 minutes
  • Board: Arduino Uno R3
  • Parts: 4

How it works

Pin 3 feeds the red LED through a 220 ohm resistor, and the LED's other leg goes to GND. When the pin is HIGH, 5 V pushes current through the LED and it lights. When the pin is LOW, the current stops.

The sketch switches the pin on, waits half a second, switches it off, and waits again. It also prints a hello line to the serial monitor once at the start.

Parts list

4 parts, plus the jumper wires. They retail for about $30; on Mokxi they're free.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
LED, red pin CArduino Uno R3 pin GND
Resistor, 220 Ω pin 1Arduino Uno R3 pin 3
LED, red pin AResistor, 220 Ω pin 2

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Blink an LED on pin 3.
//
//   pin 3 -> 220 ohm resistor -> the LED's long leg; the short leg -> GND
//
// setup() runs once and makes pin 3 an output. loop() then runs again and
// again: the pin goes HIGH (5 V, the LED lights), the board waits half a
// second, the pin goes LOW (0 V, the LED goes out), and it waits again.
//
// Without the two delays the LED would flash far too fast to see. Change the
// 500s and run it again.

const int LED_PIN = 3;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: blinking the LED on pin 3");
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Runs once at power-up. It makes LED_PIN (pin 3) an output with pinMode and starts the serial port at 9600 baud so the board can print a short message.

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: blinking the LED on pin 3");
}

loop sketch.ino

Runs again and again. digitalWrite sets the pin HIGH, delay(500) waits half a second, then the pin goes LOW and it waits again. Without the delays the blinking would be too fast to see.

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The LED never lights. This project
    LEDs have a direction. The long leg (anode) goes toward the resistor and pin 3, and the short leg goes to GND.
  • The blink is too fast or too slow. This project
    Change the two 500 values in delay. They are in milliseconds.
  • The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
    Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • The LED does not light, or it lights once and then dies. LED
    LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin.
  • A blue or white LED stays dark on 3.3 V. LED
    Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.
  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.