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
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
}void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}- Runs once when the Arduino powers on or resets
pinMode()configures a pin as either INPUT or OUTPUTLED_BUILTINis a constant that refers to pin D13 on the Arduino UNOOUTPUTmode means we will send power to this pin (not read from it)
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:
- LED turns ON (HIGH = 5V)
- Wait 1 second
- LED turns OFF (LOW = 0V)
- Wait 1 second
- Loop back to step 1 and repeat forever
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_BUILTINis a constant (a named value) that equals 13- Using
LED_BUILTINinstead of the number13makes your code more readable and portable - Different Arduino boards have LEDs on different pins, so
LED_BUILTINautomatically adapts to your board
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
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
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)
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
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)
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
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)
- Arduino UNO board
- USB cable (to program and power the Arduino)
- External LED (any color, 5mm standard size works)
- Resistor (220Ω to 1kΩ)
- Breadboard (optional but recommended)
- Jumper wires
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)
-
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
-
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
-
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
-
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!
