|

Arduino LED Blinking Project: Step-by-Step Guide with Code (2026)

Arduino LED Blinking Project: Step-by-Step Guide with Code

If you’re new to Arduino, the LED blinking project is the perfect place to start. It’s simple, requires almost no components, and teaches you the basics of how Arduino code (called a “sketch”) works. In this guide, you’ll learn exactly how to wire the circuit, upload the code, and understand what each line does.

Arduino LED blinking project

What You’ll Learn

  • How an LED blinking circuit works
  • How to wire an Arduino with an LED and resistor
  • Full working Arduino code for blinking an LED
  • How the setup() and loop() functions work
  • How to change blink speed

Components Required

ComponentQuantity
Arduino Uno (or any Arduino board)1
LED (any color)1
220-ohm resistor1
Breadboard1
Jumper wires2
USB cable (for programming)1

Note: Most Arduino boards (like the Uno) already have a built-in LED on pin 13, so you can even skip the external LED and resistor if you just want to test the code quickly.

Circuit Diagram / Wiring

  1. Connect the longer leg (anode) of the LED to digital pin 8 on the Arduino (through the resistor).
  2. Connect the shorter leg (cathode) of the LED to the GND (ground) pin on the Arduino.
  3. Place the 220-ohm resistor in series with the LED to prevent it from burning out.

Full Arduino Code

cpp

// Arduino LED Blinking Project
// Blinks an LED connected to pin 8

int ledPin = 8; // Define the pin where the LED is connected

void setup() {
  pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}

void loop() {
  digitalWrite(ledPin, HIGH); // Turn the LED ON
  delay(1000);                // Wait for 1 second (1000 milliseconds)
  digitalWrite(ledPin, LOW);  // Turn the LED OFF
  delay(1000);                // Wait for 1 second
}

Code Explanation (Line by Line)

  • int ledPin = 8; — This creates a variable to store which pin the LED is connected to. Makes the code easier to update later.
  • pinMode(ledPin, OUTPUT); — Inside setup(), this tells Arduino that pin 8 will send power out (not read input). setup() runs only once when the board starts.
  • digitalWrite(ledPin, HIGH); — Sends 5V to the pin, turning the LED ON.
  • delay(1000); — Pauses the program for 1000 milliseconds (1 second).
  • digitalWrite(ledPin, LOW); — Sends 0V to the pin, turning the LED OFF.
  • loop() — Everything inside this function repeats forever, which is why the LED keeps blinking.

How to Upload the Code

  1. Open the Arduino IDE on your computer (download it from arduino.cc if you don’t have it).
  2. Connect your Arduino board to your computer using a USB cable.
  3. Go to Tools > Board and select your Arduino model (e.g., “Arduino Uno”).
  4. Go to Tools > Port and select the correct COM port.
  5. Paste the code above into a new sketch.
  6. Click the Upload button (right arrow icon).
  7. Once uploaded, your LED should start blinking every second.
sketch_led_blink | Arduino IDE Upload // Arduino LED Blinking Project int ledPin = 8;void setup () { pinMode (ledPin, OUTPUT); }void loop () { digitalWrite (ledPin, HIGH); delay (1000); digitalWrite (ledPin, LOW); delay (1000); Uploading… Sketch uses 924 bytes of program storage space. Arduino Uno on COM5

How to Change the Blink Speed

Want the LED to blink faster or slower? Just change the number inside delay().

  • delay(500); → blinks twice as fast (0.5 second on, 0.5 second off)
  • delay(2000); → blinks slower (2 seconds on, 2 seconds off)

Troubleshooting Common Issues

  • LED doesn’t light up: Check that the longer leg (anode) is connected to pin 8 and the shorter leg (cathode) is connected to GND. LEDs only work in one direction.
  • Upload fails / “port not found”: Make sure the correct board and port are selected under the Tools menu, and try a different USB cable/port.
  • LED stays on or off permanently: Double check the code was uploaded successfully — look for “Done uploading” in the IDE status bar.

What’s Next?

Once you’re comfortable with this project, try these beginner-friendly upgrades:

  • Blink two LEDs alternately
  • Control LED blinking speed using a potentiometer
  • Add a push button to turn the LED on/off manually
  • Use millis() instead of delay() for non-blocking blinking (a more advanced technique)

Conclusion

The LED blinking project may look simple, but it teaches you the core structure of every Arduino program: setup() for one-time configuration and loop() for repeating actions. Master this, and you’re ready to move on to sensors, motors, and more advanced Arduino projects.

Similar Posts

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *