Arduino Blink LED Tutorial

Arduino Blink LED Tutorial: Onboard & External LEDs

What You'll Need

Step-by-Step Wiring for External LED

Follow these simple steps to connect an external LED to your Arduino:

How the Code Works

This code makes an LED blink on and off at 1-second intervals. It works with both onboard and external LEDs.

Main Functions in Arduino Code

Arduino Code

Copy and paste the code below into the Arduino IDE:


// Blink LED on Arduino (Onboard or External)

// This function runs once when the Arduino starts
void setup() {
  // Initialize pin 13 as an output pin for the LED
  pinMode(13, OUTPUT);
}

// This function runs repeatedly in a loop
void loop() {
  // Turn the LED on (set pin 13 to HIGH)
  digitalWrite(13, HIGH);
  delay(1000); // Wait for one second
  
  // Turn the LED off (set pin 13 to LOW)
  digitalWrite(13, LOW);
  delay(1000); // Wait for one second
}
                

How to Upload the Code

  1. Connect your Arduino to your PC using a USB cable.
  2. Open the Arduino IDE and paste the code above into the editor.
  3. Select your board type and the correct COM port in the IDE.
  4. Click the upload button to send the code to the Arduino.
  5. The LED (onboard or external) should now blink every second.

Tips for Success

Conclusion

Congratulations! You’ve successfully created a simple blinking LED project using Arduino. This foundational project is an excellent starting point for exploring more complex circuits and coding challenges. Stay tuned for more tutorials at Microautomation.no!