Skip to content

Sahil-Hossain-1429/Arduino-BlinkingLed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Arduino-BlinkingLed

Preview

Arduino BLink

Project Overview

This is a beginner-friendly Arduino project that makes an LED blink on and off repeatedly. The LED turns on for 1 second, then off for 1 second, in an infinite loop.

Difficulty Level: Beginner
Components Needed: Arduino UNO, LED, Resistor (220Ω recommended), Breadboard, Jumper wires


The Code

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // change state of the LED by setting the pin to the HIGH voltage level
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // change state of the LED by setting the pin to the LOW voltage level
  delay(1000);                      // wait for a second
}

Code Explanation

The setup() Function

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}
  • Runs once when the Arduino powers on or resets
  • pinMode() configures a pin as either INPUT or OUTPUT
  • LED_BUILTIN is a constant that refers to pin D13 on the Arduino UNO
  • OUTPUT mode means we will send power to this pin (not read from it)

The loop() Function

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // Turn LED ON
  delay(1000);                      // Wait 1 second (1000 milliseconds)
  digitalWrite(LED_BUILTIN, LOW);   // Turn LED OFF
  delay(1000);                      // Wait 1 second
}
  • Runs repeatedly forever after setup() completes
  • digitalWrite() sets a pin to either HIGH (5 volts) or LOW (0 volts)
  • delay() pauses execution for the specified milliseconds
    • 1000 milliseconds = 1 second
    • 2000 milliseconds = 2 seconds

Execution Flow:

  1. LED turns ON (HIGH = 5V)
  2. Wait 1 second
  3. LED turns OFF (LOW = 0V)
  4. Wait 1 second
  5. Loop back to step 1 and repeat forever

Detailed Component Explanation

1. Why is D13 the LED_BUILTIN?

Short Answer: The Arduino UNO has a physical LED already soldered to pin D13. That's why D13 is the default LED_BUILTIN.

Details:

  • The Arduino UNO board comes with a built-in LED connected to digital pin 13 (D13)
  • The manufacturer already included the resistor on the board to protect the LED
  • LED_BUILTIN is a constant (a named value) that equals 13
  • Using LED_BUILTIN instead of the number 13 makes your code more readable and portable
  • Different Arduino boards have LEDs on different pins, so LED_BUILTIN automatically adapts to your board

2. Why Do You Insert the Pin in D13?

Short Answer: D13 is the digital pin connected to the LED. When you set it to HIGH, electricity flows to the LED.

Details:

  • D stands for "Digital"
  • Arduino has two types of pins:
    • Digital Pins (D0-D13): Can be either HIGH (5V) or LOW (0V)
    • Analog Pins (A0-A5): Can read varying voltage levels (0V to 5V)
  • When you write digitalWrite(13, HIGH), you're telling pin 13 to output 5 volts
  • This voltage flows through the resistor and LED, making it light up
  • D13 is just the physical location on the board where this LED is connected

3. What is a Resistor?

Short Answer: A resistor limits the flow of electricity (called current).

Details:

  • A resistor is an electronic component that restricts how much electricity can flow through it
  • Measured in ohms (Ω)
  • Examples:
    • 220Ω (220 ohms) - restricts more current
    • 1kΩ (1000 ohms) - restricts even more current
    • 10Ω (10 ohms) - restricts very little current
  • Think of it like a water valve:
    • Fully open = lots of water flows
    • Partially closed = less water flows
    • Same concept with electricity and resistors

Common resistor values for LEDs:

  • 220Ω to 1kΩ (most common for Arduino projects)
  • Higher values = dimmer LED
  • Lower values = brighter LED

4. Why Do You Need a Resistor Here?

Short Answer: LEDs are sensitive to too much current. A resistor protects the LED from burning out.

Details:

Without a Resistor:

  • Arduino pin D13 outputs 5 volts at full capacity
  • Most LEDs only want 2-3 volts and about 20 milliamps (mA) of current
  • If you connect an LED directly without a resistor, it gets way too much current
  • Result: The LED will burn out instantly (you'll see it glow very brightly for a moment, then stop working forever)

With a Resistor:

  • The resistor drops some of the voltage (usually 2-3 volts)
  • This limits the current to a safe level (around 20mA)
  • The LED gets exactly what it needs to light up safely
  • Result: The LED works properly and lasts for a long time

Analogy:

  • A resistor is like a pressure regulator on a fire hose
  • Without it, the hose bursts from too much pressure
  • With it, the water flows at a safe pressure and you can actually use it

How to Calculate Resistor Value (for reference):

Resistor Value = (Supply Voltage - LED Voltage) / Desired Current
Example: (5V - 2V) / 0.02A = 150Ω
(Use 220Ω or 1kΩ, common values that work well)

5. What Happens If You Don't Connect Like It Says?

If you skip the resistor (connect LED directly to pin and GND):

  • The LED will burn out within seconds
  • You'll see it glow very brightly momentarily
  • Then it stops working permanently
  • The Arduino pin might also be damaged

If you reverse the LED polarity (swap long and short legs):

  • Nothing bad happens
  • The LED simply won't light up
  • LEDs only work in one direction (they're polarized)
  • Reversing it won't damage the LED; it just won't turn on

If you skip one of the connections entirely:

  • The circuit is incomplete (broken loop)
  • No electricity flows
  • The LED won't light up
  • Nothing gets damaged

If you connect both legs to the same voltage:

  • There's no voltage difference for electricity to flow
  • The LED won't light up
  • Nothing is damaged

6. What is GND?

Short Answer: GND stands for "Ground." It's the reference point for 0 volts and the return path for electricity.

Details:

  • GND is the negative terminal of the power source (like the - on a battery)
  • All GND pins on the Arduino are connected together internally
  • It's called "ground" because it's the baseline reference voltage (0V)
  • Every circuit needs a complete path, and GND provides that return path

Voltage Comparison:

  • HIGH = 5 volts above GND
  • GND = 0 volts (the reference point)
  • Voltage difference = 5V - 0V = 5V

In your Arduino:

  • One side of the circuit is positive (D13 at 5V)
  • The other side is negative (GND at 0V)
  • Electricity always flows from positive to negative (from HIGH to GND)

7. Why Do You Need GND?

Short Answer: Electricity needs a complete circle to flow. GND completes that circle.

Details:

The Complete Circuit Path:

Arduino D13 (5V) 
    ↓ (HIGH voltage)
[Resistor]
    ↓ (voltage drops)
[LED - lights up]
    ↓
GND (0V)
    ↓
[Back to Arduino Ground]
    ↓ (electricity returns)
Arduino D13 (ready for next cycle)

Why both are essential:

  • D13 provides: The starting point (positive voltage, the push)
  • GND provides: The return point (negative reference, the pull)
  • Both together: Create a voltage difference that pushes electricity through

8. What Happens If You Remove the GND?

Short Answer: The circuit breaks. The LED won't light up, and nothing gets damaged.

Details:

Without GND connection:

  • The circuit loop is incomplete
  • Electricity cannot flow
  • No current = no problem (nothing is damaged)
  • The LED simply stays dark

Key Insight:

  • Missing connections = LED doesn't work (safe, just non-functional)
  • Wrong resistor value = LED might dim/brighten but still works
  • No resistor = LED gets destroyed (dangerous)
  • Reversed polarity = LED just doesn't light (safe)

How to Build the Circuit

Components You Need:

  1. Arduino UNO board
  2. USB cable (to program and power the Arduino)
  3. External LED (any color, 5mm standard size works)
  4. Resistor (220Ω to 1kΩ)
  5. Breadboard (optional but recommended)
  6. Jumper wires

Step-by-Step Instructions:

Option 1: Using the Built-in LED (Easiest)

  • Upload the code as-is
  • No external components needed
  • The LED on the board (next to pin D13) will blink

Option 2: Using an External LED (More Educational)

  1. Connect the resistor:

    • Insert one end of the resistor into Arduino Uno pin D13
    • Insert the other end into an empty row on the breadboard
  2. Connect the LED:

    • Take the long leg (anode) of the LED
    • Insert it into the same breadboard row as the resistor's other end
    • Take the short leg (cathode) of the LED
    • Insert it into another row on the breadboard
  3. Connect to GND:

    • Use a jumper wire to connect the LED's short leg row to the Arduino GND pin
    • You can use any of the GND pins on the Arduino
  4. Upload the code

    • Connect the Arduino to your computer with the USB cable
    • Open the Arduino IDE
    • Paste the code into a new sketch
    • Click Upload
    • The LED should start blinking!

Resource

  1. Arduino Blink

About

This is a beginner-friendly Arduino project that makes an LED blink on and off repeatedly. The LED turns on for 1 second, then off for 1 second, in an infinite loop.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages