Blinking an LED using an Arduino is one of the most basic and common beginner projects. Here's how to do it:
Hardware Required
- 1 × Arduino board (e.g., Arduino Uno, Nano, etc.)
- 1 × LED
- 1 × 220Ω resistor
- Breadboard and jumper wires
OR
You can use the onboard LED (usually on pin 13) — no external components needed.
Circuit Diagram (for external LED)
less
[Arduino Pin 13] --- [220Ω Resistor] ---|> (LED) --- GND
- Connect the long leg (anode) of the LED to pin 13 through the resistor.
- Connect the short leg (cathode) to GND.
Arduino Code (Using Built-in LED)
cpp
void setup() {
pinMode(13, OUTPUT); // Set pin 13 as output
}
void loop() {
digitalWrite(13, HIGH); // Turn LED on
delay(1000); // Wait for 1 second
digitalWrite(13, LOW); // Turn LED off
delay(1000); // Wait for 1 second
}
This will make the LED blink on and off every second.
Upload the Code
- Open the Arduino IDE.
- Select the correct board and port under the "Tools" menu.
- Copy the code into the IDE.
- Click Upload.
Summary
To blink an LED with Arduino:
- Set the LED pin as OUTPUT in setup().
- Use digitalWrite() and delay() inside loop() to turn it on and off repeatedly.
This is a great first step to learning digital output control on microcontrollers!
Top comments (1)
I recommend to you read this article dev.to/snorri1986/replace-delay-2k4f.
It is about how to replace delay() function.
Happy coding with Arduino.