Skip to content
muhcihan
ArduinoRoboticsBeginnerEducation

First Steps with Arduino: Blinking an LED

The first project where electronics meets code. While blinking an LED with Arduino, we learn setup, loop and digital output.

Cihan Akgün2 min read
On this page
  1. What you need
  2. Build the circuit
  3. Write the code
  4. What does the code do?
  5. Try it yourself

In every programming language, the first program prints "Hello World". In electronics, the equivalent is blinking an LED: the classic Blink. In this post we'll build your first Arduino project step by step, even if you've never done it before.

What you need

PartQtyNote
Arduino Uno1Or any compatible board
LED1Any color
220 Ω resistor1Protects the LED
Breadboard and jumper wires—No soldering needed

Build the circuit

  1. Connect the LED's long leg (+, anode) to one end of the 220 Ω resistor.
  2. Connect the other end of the resistor to Arduino digital pin 13.
  3. Connect the LED's short leg (−, cathode) to Arduino GND.

The resistor limits the current through the LED. Without it, the LED draws too much current and can burn out quickly.

Write the code

blink.ino
cpp
const int LED_PIN = 13; // pin the LED is connected to
 
void setup() {
  pinMode(LED_PIN, OUTPUT); // set the pin as an output
}
 
void loop() {
  digitalWrite(LED_PIN, HIGH); // LED on (5V)
  delay(1000);                 // wait 1 second
  digitalWrite(LED_PIN, LOW);  // LED off (0V)
  delay(1000);                 // wait 1 second
}

What does the code do?

  • setup() runs once when the board powers up. Here we set pin 13 as an output.
  • loop() repeats forever while the board is on.
  • digitalWrite(pin, HIGH) puts 5 volts on the pin and the LED turns on; LOW puts 0 volts and the LED turns off.
  • delay(1000) pauses the program for 1000 milliseconds, or 1 second.

Try it yourself

If your code runs, congratulations, you've written your first embedded program! Now a small challenge:

  1. Change the delay values to make the LED blink faster.
  2. Add a second LED and light them in turn to make a traffic light.
  3. Send an SOS (... --- ...) in Morse code with the LED.

We build these topics together in my lessons

Online robotics coding lessons for primary, middle and high school students.