⭐ Beginner
⏱️ 10 minutes
Blinking Light
Your first project! An LED turns on and off again and again, just like a blinking light. This is how you learn how the Arduino turns an output on and off.
🧰 What do you need?
🗺️ Wiring diagram
Follow the wires from the Arduino to each part. You can choose the wire colors yourself.
| From | To |
|---|---|
Arduino UNO · D13 |
Resistor 220 Ω · 1 |
Resistor 220 Ω · 2 |
LED (little light) · ANODE |
LED (little light) · CATHODE |
Arduino UNO · GND |
🛠️ This is how you build it
- Put the LED in the breadboard, with the legs in two different rows.
- Put a 220 Ω resistor from the row with the long leg to another row.
- Connect that other row with a wire to pin 13 of your Arduino.
- Connect the short leg with a wire to GND.
💻 The code
// Blinking light
// An LED turns on and off again and again, just like a blinking light.
const int LED_PIN = 13; // The LED is on pin 13 (through the 220 ohm resistor)
const int WAIT_TIME = 500; // How long the LED stays on or off (in milliseconds)
void setup() {
// setup() runs once when the Arduino starts
pinMode(LED_PIN, OUTPUT); // Pin 13 is an output: it gives power
}
void loop() {
// loop() runs again and again, forever
digitalWrite(LED_PIN, HIGH); // LED on
delay(WAIT_TIME); // Wait a moment
digitalWrite(LED_PIN, LOW); // LED off
delay(WAIT_TIME); // Wait a moment
}
🧠 What does the code do?
- In
setup()we say that pin 13 is an output. - In
loop()we turn the LED on, wait a moment, turn it off, and wait again. - After that,
loop()just starts over. So the LED keeps blinking.
🎯 Try this…
- Make the LED blink twice as fast
- Make it an SOS signal: short-short-short, long-long-long, short-short-short
- Make the LED slowly get bright and dim, as if it is breathing
🚀 Build this project with Codey: open codey.online/starter-kits/uno/projects/blink and click MAKE THIS. Then the code and the wiring diagram are ready right away.
Codey Online is a product of OTRONIC