DEV Community

Hedy
Hedy

Posted on

How to blink an LED using Arduino?

Blinking an LED using an Arduino is one of the most basic and common beginner projects. Here's how to do it:

Hardware Required

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
Enter fullscreen mode Exit fullscreen mode
  • 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
}
Enter fullscreen mode Exit fullscreen mode

This will make the LED blink on and off every second.

Upload the Code

  1. Open the Arduino IDE.
  2. Select the correct board and port under the "Tools" menu.
  3. Copy the code into the IDE.
  4. Click Upload.

Summary
To blink an LED with Arduino:

  1. Set the LED pin as OUTPUT in setup().
  2. 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)

Collapse
 
snorri1986 profile image
Denys Shabelnyk

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.