What You'll Need
- 1 x Arduino Board (e.g., Arduino Uno with onboard LED)
- 1 x External LED (optional)
- 1 x Resistor (220Ω) (if using an external LED)
- Breadboard and jumper wires (optional)
- USB cable to connect Arduino to PC
Step-by-Step Wiring for External LED
Follow these simple steps to connect an external LED to your Arduino:
- Connect the long leg (anode) of the LED to digital pin 13.
- Attach the short leg (cathode) to one end of a 220Ω resistor.
- Connect the other end of the resistor to the Arduino's GND (ground) pin.
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
setup()
: Runs once when the program starts, initializing pin 13 as an output.loop()
: Contains the main logic and repeats continuously to make the LED blink.pinMode()
: Sets pin 13 as an output to control the LED.digitalWrite()
: Sends a HIGH or LOW signal to pin 13 to turn the LED on or off.delay()
: Pauses the program for a specific duration (e.g., 1000ms = 1 second).
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
- Connect your Arduino to your PC using a USB cable.
- Open the Arduino IDE and paste the code above into the editor.
- Select your board type and the correct COM port in the IDE.
- Click the upload button to send the code to the Arduino.
- The LED (onboard or external) should now blink every second.
Tips for Success
- Ensure the LED and resistor are connected correctly to avoid damaging the components.
- Double-check the board and port selection in the Arduino IDE before uploading the code.
- If the LED doesn't blink, verify your wiring and connections.
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!