In this lesson, we will learn the very basics of using Arduino by making a simple blinking LED project with Arduino.
List of Content
- List of Components
- Connections: Blinking LED Circuit Schematics
- The Code and How It Works
- How to Go Further in Your Blinking LED Circuit
1. Needed Components
- Arduino Board (Arduino Uno or another type)
- LED (any color)
- Resistor (330 ohm)
- Breadboard
- Jumper Wires
- Power Supply (USB cable or battery pack)
2. Connecting Your Blinking LED Circuit
Set Up the Breadboard:
- Place the LED on the breadboard. The longer leg (anode) is the positive side, and the shorter leg (cathode) is the negative side.
- Connect the anode of the LED to a digital pin on the Arduino (e.g., pin 13).
- Connect one leg of the 330-ohm resistor to the cathode of the LED, and connect the other leg of the resistor to the ground (GND) on the Arduino.
Schematics and Pictures
- First connection option: LED connected directly to the Arduino pin with a resistor to GND.
- Second connection option: LED and resistor connected in series to the Arduino pin and GND.
3. Code
Here’s a simple Arduino code to make the LED blink:
// Define pin number
const int ledPin = 13; // LED connected to digital pin 13
void setup() {
// Set pin mode
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
// Turn the LED on
digitalWrite(ledPin, HIGH); // Send HIGH signal to turn on the LED
delay(1000); // Wait for 1 second (1000 milliseconds)
// Turn the LED off
digitalWrite(ledPin, LOW); // Send LOW signal to turn off the LED
delay(1000); // Wait for 1 second
}
How This Code Works:
- Variable Declaration: At the beginning, we store the number
13
into the variableledPin
to represent the pin where the LED is connected. - Setup: The
pinMode()
function sets theledPin
as an output pin, meaning it will send signals to the LED. - Loop:
- The
digitalWrite()
function turns the LED on by sending aHIGH
signal and off by sending aLOW
signal. - The
delay()
function pauses the program for a specified time (in milliseconds). Here, it pauses for 1 second between turning the LED on and off.
4. Tips for Modification
Now that you you know how to make a simple blinking LED project with Arduino, it may be a good idea to take the next step
- Change Blinking Speed: Modify the
delay()
values to make the LED blink faster or slower.
- Example:
delay(500)
for 0.5 seconds ordelay(2000)
for 2 seconds.
- Multiple LEDs: Add more LEDs and control them independently by connecting them to different pins and modifying the code. When you are done, check our traffic light project.
- Patterns: Create custom blinking patterns, such as Morse code or alternating blinks between multiple LEDs.
- Brightness Control: Use PWM (Pulse Width Modulation) pins (marked with ~, pins 3, 5, 6, 9, 10, or 11 on Arduino Uno) and the
analogWrite()
function to control the LED brightness. Ex: analogWrite(3,124) for halfing brightness. - External Input: Add a push button to control when the LED blinks, as in our lesson 3. For example, the LED only blinks when the button is pressed.
This simple blinking LED project is a great starting point for learning Arduino. You can expand it in countless ways as you gain more experience! Enjoy experimenting!
Leave a Reply