Arduino

Blink led with arduino

0
arduino led blink

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:

  1. LED: The longer leg of the LED (anode, positive) connects through the resistor to a digital pin on your Arduino (e.g., pin 13).
  2. Resistor: The other end of the resistor connects to the shorter leg of the LED (cathode, negative).
  3. Ground: Connect the Arduino’s GND pin to the breadboard’s ground rail (if using) or directly to the LED’s shorter leg.
arduino led blink

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
}
ard

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:

  1. Connect your Arduino to your computer using a USB cable.
  2. Open the Arduino IDE.
  3. Paste the code into the IDE.
  4. Select your Arduino board and port from the “Tools” menu.
  5. 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.

Let me know if you’d like to explore different blinking patterns or have any more questions!

Elect101

An easy DC-to-DC boost converter that can efficiently convert 6V to 100V

Previous article

Simple push-pull inverter project with IR2153

Next article

You may also like

Comments

Leave a reply

More in Arduino