Your First LED Blink

Create your first Arduino program to make an LED blink.

ARDUINO LESSONSProgrammingLED Projects
S
Shaun Sosi
Arduino Basics: Make an LED Blink with Code

Your First Arduino Program

Making an LED blink is the "Hello, World!" of Arduino programming. It's a simple yet powerful way to learn the basics of Arduino coding and hardware interaction.

LED Circuit Setup
LED circuit setup with Arduino and breadboard

Getting Started Tip!

Before diving into the code, make sure you have your Arduino kit ready. We'll be using an LED, resistor, and jumper wires for this project.

Essential Tools

To follow along with this tutorial, you'll need the Arduino kit:

Component Check:

  • Arduino Board - The main microcontroller board
  • LED - A standard LED for the blinking effect
  • 220Ω Resistor - To protect the LED from too much current
  • Jumper Wires - Two wires to connect the circuit

Essential Arduino Functions

Let's understand the key functions we'll be using:

  • pinMode() - Configures a pin as either INPUT or OUTPUT pinMode(7, OUTPUT);

  • digitalWrite() - Sets a pin to HIGH (5V) or LOW (0V) digitalWrite(7, HIGH);

  • delay() - Pauses the program for a specified time in milliseconds delay(1000); // Waits for 1 second

Syntax Tip!

Remember to end each instruction with a semicolon (;) - it's like a period at the end of a sentence in Arduino code.

The Blink Code

Here's the complete code to make your LED blink:

LEDBlink.ino
void setup() { // put your setup code here, to run once: pinMode(7, OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(7, HIGH); // Turn the LED on delay(1000); // Wait for 1 second digitalWrite(7, LOW); // Turn the LED off delay(1000); // Wait for 1 second }

    Time Conversion:

    • 1000ms - Equal to 1 second
    • 500ms - Equal to 0.5 seconds
    • 2000ms - Equal to 2 seconds

    Code Explanation

    Let's break down how the code works:

    1. Setup Function

      pinMode(7, OUTPUT); tells Arduino that pin 7 will be used to send signals (OUTPUT mode)

    2. Loop Function - First Part

      digitalWrite(7, HIGH); sends 5V to pin 7, turning the LED on delay(1000); makes the program wait for 1 second

    3. Loop Function - Second Part

      digitalWrite(7, LOW); sends 0V to pin 7, turning the LED off delay(1000); makes the program wait for another second

    4. Continuous Operation

      The loop function repeats indefinitely, creating the blinking effect

    Common Mistakes to Avoid:

    • Missing Semicolons - Always end your code lines with a semicolon
    • State Confusion - Double-check your HIGH and LOW states are correct
    • Pin Numbers - Verify you're using the correct pin number in your code
    • Delay Values - Make sure your timing values are in milliseconds

    Experiment Ideas

    Now that you've got the basic blink working, try these variations:

    • Change the Timing - Try different delay values to make the LED blink faster or slower
    • Add More LEDs - Connect more LEDs to different pins and create patterns
    • Create Sequences - Make multiple LEDs blink in a specific order
    • Morse Code - Use the blink pattern to spell out messages in Morse code

    Coming Up Next:

    In our next episode, we'll explore more complex Arduino projects and programming concepts!

    Connect With Me

    Support Our Work

    Help us create more amazing content

    $

    Your contribution helps us create more amazing content. Thank you! 💖