Cipad 11: 10e Leçon: Comment réaliser un Contrôleur pour LED RGB
Table of Contents
Introduction
In this tutorial, you will learn how to create a RGB LED controller using Arduino, a project that is perfect for beginners. This project will not only help you understand how to control RGB LEDs but also introduce you to basic programming concepts and circuit design.
Step 1: Gather Materials
Before starting, ensure you have the following materials:
- Arduino board (e.g., Arduino Uno)
- RGB LED
- 220 ohm resistors (3)
- Breadboard
- Jumper wires
- Power source for the Arduino
- Optional: TinkerCad for simulation
Step 2: Understand the RGB LED
An RGB LED is made up of three individual LEDs (red, green, and blue) that can be combined to create various colors. Here’s how to identify the pins:
- The longest pin is the common anode/cathode.
- The other three pins correspond to red, green, and blue.
Step 3: Set Up the Circuit
- Place the RGB LED on the breadboard.
- Connect the common anode (or cathode) pin to the positive rail of the breadboard.
- Connect the red, green, and blue pins to separate digital pins on the Arduino (e.g., pins 9, 10, and 11).
- Connect a 220-ohm resistor to each of the color pins.
- Connect the other end of each resistor to the ground rail of the breadboard.
Step 4: Write the Arduino Code
Below is a basic code snippet to control the RGB LED. You can modify the colors and patterns as desired.
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Set color to red
digitalWrite(redPin, HIGH);
delay(1000);
digitalWrite(redPin, LOW);
// Set color to green
digitalWrite(greenPin, HIGH);
delay(1000);
digitalWrite(greenPin, LOW);
// Set color to blue
digitalWrite(bluePin, HIGH);
delay(1000);
digitalWrite(bluePin, LOW);
// Set color to purple
digitalWrite(redPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(1000);
digitalWrite(redPin, LOW);
digitalWrite(bluePin, LOW);
}
Step 5: Upload the Code
- Connect your Arduino to your computer.
- Open the Arduino IDE and paste the code into a new sketch.
- Select the correct board and port from the Tools menu.
- Click the upload button to transfer the code to your Arduino.
Step 6: Test Your Setup
Once the code is uploaded:
- Power the Arduino.
- Observe the RGB LED cycling through the colors as programmed.
- If it does not work, double-check your connections and code for errors.
Conclusion
You have successfully built an RGB LED controller using Arduino! This project enhances your understanding of electronic components, coding, and circuit design. Consider experimenting with different color combinations and patterns in your code. For further practice, try integrating sensors or remote control functionality to expand your project. Happy coding!