Tutorial 17 – Controlling Multiple LEDs with Arduino
Welcome back to CraftedTech Engineering's Arduino tutorial series! In this tutorial, we’ll show you how to control multiple LEDs with your Arduino. This will introduce you to parallel wiring and give you experience in controlling multiple outputs simultaneously.
🔌 What You’ll Need
- 1 Arduino Board (e.g., Arduino UNO)
- 3 LEDs (any colors you like)
- 3 220Ω Resistors
- Breadboard
- Jumper wires
- USB cable for Arduino
You can order the required components here:
🧠 What Is Controlling Multiple LEDs?
When working with multiple LEDs, you can control them individually or simultaneously. This tutorial will teach you how to wire and control three LEDs, each connected to a different pin on the Arduino.
🧾 Step-by-Step Instructions
🔧 Step 1: Wiring the LEDs
- Connect the long leg (anode) of each LED to the digital pins on the Arduino (e.g., pin 3, pin 4, and pin 5).
- Connect the short leg (cathode) of each LED to one end of a 220Ω resistor.
- Connect the other end of each resistor to GND (ground) on the Arduino.
💻 Step 2: Arduino Code to Control Multiple LEDs
int led1 = 3; // LED 1 connected to digital pin 3
int led2 = 4; // LED 2 connected to digital pin 4
int led3 = 5; // LED 3 connected to digital pin 5
void setup() {
pinMode(led1, OUTPUT); // Set LED 1 as an output
pinMode(led2, OUTPUT); // Set LED 2 as an output
pinMode(led3, OUTPUT); // Set LED 3 as an output
}
void loop() {
digitalWrite(led1, HIGH); // Turn LED 1 on
digitalWrite(led2, LOW); // Turn LED 2 off
digitalWrite(led3, LOW); // Turn LED 3 off
delay(1000); // Wait for 1 second
digitalWrite(led1, LOW); // Turn LED 1 off
digitalWrite(led2, HIGH); // Turn LED 2 on
digitalWrite(led3, LOW); // Turn LED 3 off
delay(1000); // Wait for 1 second
digitalWrite(led1, LOW); // Turn LED 1 off
digitalWrite(led2, LOW); // Turn LED 2 off
digitalWrite(led3, HIGH); // Turn LED 3 on
delay(1000); // Wait for 1 second
}
🔍 Code Breakdown
- pinMode(): Sets each pin connected to the LEDs as an output.
- digitalWrite(): Turns the LEDs on (HIGH) or off (LOW).
- delay(): Waits for a specified time in milliseconds before moving to the next line of code.
🧪 Try This!
- Experiment by changing the timing in the delay() function and watch how the LEDs turn on and off.
- You can also try turning on all LEDs at once by setting all pins to HIGH at the same time.
🛠️ Troubleshooting Tips
- Double-check the pin connections for each LED and resistor.
- Ensure each LED is connected in the correct orientation (long leg to pin, short leg to resistor).
- Make sure that the resistors are used to limit the current flowing through the LEDs.
🧭 What You Learned in This Tutorial
✔️ How to wire and control multiple LEDs using Arduino
✔️ How to use digital pins and control multiple outputs
✔️ How to use delay() to create time-based effects
✔️ How to create simple light patterns by controlling multiple LEDs
📌 Next Up: Tutorial 18 – Using a Button to Control an LED
In the next tutorial, we’ll learn how to use a pushbutton to control an LED and explore input/output interaction.
📣 Don’t forget to follow CraftedTech Engineering for more hands-on tutorials and project ideas!
🔗 Website: craftedtechengineering.com
📘 Facebook: @CraftedTechEngineering
📺 YouTube: @CraftedTechEngineering