Post

Arduino Blink Project - Getting Started with Embedded Systems

A beginner-friendly Arduino project demonstrating the classic "Hello World" of embedded programming - making an LED blink

Arduino Blink Project - Getting Started with Embedded Systems

Overview

The “Blink” project is the classic first program for Arduino and embedded systems. This project demonstrates how to control an LED using an Arduino board, introducing fundamental concepts like digital I/O, timing, and basic embedded programming.

Components Required

  • Arduino Uno (or compatible board)
  • LED (any color)
  • 220Ω resistor (or 330Ω)
  • Breadboard
  • Jumper wires

Circuit Setup

Wiring Diagram

flowchart LR
    A[Arduino Pin 13] -->|digital output| R[220 Ω resistor]
    R --> LED[LED anode +]
    LED -->|cathode –| GND[GND]

Pin Connections

  • LED Anode (long leg) → Resistor → Arduino Digital Pin 13
  • LED Cathode (short leg)Arduino GND

Note: Arduino Uno has a built-in LED on pin 13, so you can test without external components!

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
  Blink
  Turns an LED on for one second, then off for one second, repeatedly.
*/

// Pin 13 has an LED connected on most Arduino boards

// The setup function runs once when you press reset or power the board
void setup() {
  // Initialize digital pin 13 as an output
  pinMode(LED_BUILTIN, OUTPUT);
}

// The loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // Turn the LED on (HIGH is the voltage level)
  delay(1000);                   // Wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // Turn the LED off by making the voltage LOW
  delay(1000);                   // Wait for a second
}

Enhanced Version with Multiple LEDs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
  Multi-LED Blink
  Controls multiple LEDs with different blink patterns
*/

// Define LED pins
int led1 = 13;
int led2 = 12;
int led3 = 11;

void setup() {
  // Initialize all pins as outputs
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}

void loop() {
  // Blink LED 1
  digitalWrite(led1, HIGH);
  delay(200);
  digitalWrite(led1, LOW);
  delay(200);
  
  // Blink LED 2
  digitalWrite(led2, HIGH);
  delay(200);
  digitalWrite(led2, LOW);
  delay(200);
  
  // Blink LED 3
  digitalWrite(led3, HIGH);
  delay(200);
  digitalWrite(led3, LOW);
  delay(200);
}

Advanced: Fade Effect (PWM)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
  Fade LED
  Demonstrates PWM (Pulse Width Modulation) for smooth brightness control
*/

int ledPin = 9;  // Must be a PWM pin (3, 5, 6, 9, 10, 11 on Uno)
int brightness = 0;
int fadeAmount = 5;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Set the brightness
  analogWrite(ledPin, brightness);
  
  // Change brightness for next time through the loop
  brightness = brightness + fadeAmount;
  
  // Reverse the direction of fading at the ends
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  
  // Wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Upload Instructions

  1. Connect Arduino to your computer via USB
  2. Open Arduino IDE
  3. Select Board: Tools → Board → Arduino Uno
  4. Select Port: Tools → Port → (your Arduino port)
  5. Copy code into the IDE
  6. Click Upload (→ button) or press Ctrl+U
  7. Observe the LED blinking!

Code Explanation

Key Functions

  • pinMode(pin, mode): Configures a pin as INPUT or OUTPUT
  • digitalWrite(pin, value): Sets a digital pin HIGH (5V) or LOW (0V)
  • analogWrite(pin, value): Writes PWM value (0-255) to a pin
  • delay(ms): Pauses execution for specified milliseconds

Understanding the Code Flow

  1. setup(): Runs once at startup
    • Configures pins
    • Initializes variables
    • Sets up serial communication (if needed)
  2. loop(): Runs continuously
    • Main program logic
    • Executes repeatedly until power off

Troubleshooting

LED Not Blinking

  • Check wiring connections
  • Verify LED polarity (long leg = anode/positive)
  • Ensure resistor is connected
  • Check if correct pin number is used
  • Try built-in LED on pin 13 first

Upload Errors

  • Verify correct board selected
  • Check USB cable connection
  • Ensure correct COM port selected
  • Try pressing reset button on Arduino

LED Too Dim/Bright

  • Adjust resistor value (lower = brighter, but don’t go below 100Ω)
  • Check if LED is rated for 5V (most are 2-3V)

Extensions & Variations

1
2
3
4
5
6
7
8
9
10
11
int blinkDelay = 100;  // milliseconds

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(blinkDelay);
  digitalWrite(ledPin, LOW);
  delay(blinkDelay);
  
  // Speed up over time
  blinkDelay = max(10, blinkDelay - 5);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int ledPin = 13;
int buttonPin = 2;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(buttonPin) == LOW) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

3. Morse Code Blinker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int ledPin = 13;

void setup(){
  pinMode(13,OUTPUT);
}

void dot() {
  digitalWrite(ledPin, HIGH);
  delay(200);
  digitalWrite(ledPin, LOW);
  delay(200);
}

void dash() {
  digitalWrite(ledPin, HIGH);
  delay(600);
  digitalWrite(ledPin, LOW);
  delay(200);
}

void loop() {
  // Blink "SOS" in Morse code: ... --- ...
  // S = ...
  dot(); dot(); dot();
  delay(400);
  // O = ---
  dash(); dash(); dash();
  delay(400);
  // S = ...
  dot(); dot(); dot();
  delay(2000);
}

Learning Outcomes

After completing this project, you should understand:

  • Basic Arduino programming structure
  • Digital I/O operations
  • Timing and delays
  • PWM for analog-like control
  • Reading schematics and wiring diagrams
  • Debugging embedded systems

Next Projects

  • Traffic Light Controller: Multiple LEDs with timing sequences
  • Potentiometer LED Dimmer: Analog input control
  • Ultrasonic Distance Sensor: Measure distance and blink based on proximity
  • RGB LED Color Mixer: Control color using PWM on multiple pins

Resources

This post is licensed under CC BY 4.0 by the author.