Today i will show you how to blink an led with arduino uno or arduino nano
Materials:
- Arduino board (Uno, Nano, etc.)
- LED
- Resistor (220 ohms is common for most LEDs)
- Breadboard (optional, but makes connections easier)
- Jumper wires
Circuit:
- LED: The longer leg of the LED (anode, positive) connects through the resistor to a digital pin on your Arduino (e.g., pin 13).
- Resistor: The other end of the resistor connects to the shorter leg of the LED (cathode, negative).
- Ground: Connect the Arduino’s GND pin to the breadboard’s ground rail (if using) or directly to the LED’s shorter leg.
Code (Arduino IDE):
int ledPin = 13; // Choose the pin for your LED
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 one second
digitalWrite(ledPin, LOW); // Turn the LED off
delay(1000); // Wait for one second
}
Explanation:
ledPin = 13;
: Defines a variable to store the pin number where you connected the LED. This makes the code easier to change if you use a different pin.setup()
:pinMode(ledPin, OUTPUT);
: Configures the chosen pin to act as an output, meaning it can send voltage to control the LED.
loop()
:digitalWrite(ledPin, HIGH);
: Sets the pin to HIGH voltage, which turns on the LED.delay(1000);
: Pauses the program for 1000 milliseconds (1 second).digitalWrite(ledPin, LOW);
: Sets the pin to LOW voltage, turning off the LED.delay(1000);
: Another 1-second pause.
The loop()
function runs continuously, creating the blinking effect.
Uploading the Code:
- Connect your Arduino to your computer using a USB cable.
- Open the Arduino IDE.
- Paste the code into the IDE.
- Select your Arduino board and port from the “Tools” menu.
- Click the “Upload” button (arrow icon) to send the code to your Arduino.
Video Here
Troubleshooting:
- LED not blinking:
- Check circuit connections.
- Ensure the LED is oriented correctly (long leg to positive, short leg to negative).
- Verify the correct pin is used in the code.
- LED stays on or off:
- Adjust the
delay()
values to change the blink speed. - Make sure the code is uploaded successfully.
- Adjust the
Let me know if you’d like to explore different blinking patterns or have any more questions!