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
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
| Part | Qty | Note |
|---|---|---|
| Arduino Uno | 1 | Or any compatible board |
| LED | 1 | Any color |
| 220 Ω resistor | 1 | Protects the LED |
| Breadboard and jumper wires | — | No soldering needed |
Build the circuit
- Connect the LED's long leg (+, anode) to one end of the 220 Ω resistor.
- Connect the other end of the resistor to Arduino digital pin 13.
- 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
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;LOWputs 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:
- Change the
delayvalues to make the LED blink faster. - Add a second LED and light them in turn to make a traffic light.
- Send an SOS (
... --- ...) in Morse code with the LED.
