Creating Ambient Light Effect Using RGB LED Module and Arduino
by Techieguy123 in Circuits > Arduino
38 Views, 0 Favorites, 0 Comments
Creating Ambient Light Effect Using RGB LED Module and Arduino

This project demonstrates how to interface an RGB LED module with an Arduino to create stunning dynamic light effects. The RGB LED combines red, green, and blue LEDs in one module, allowing you to produce various colors by varying the brightness of each component. Inspired by creative lighting solutions, this project is ideal for beginners who want to explore LED control and learn pulse-width modulation (PWM) in Arduino.
Supplies

Assemble the Circuit


Connect the RGB LED module to the breadboard.
Identify the pins for red, green, blue, and the common pin.
Connect the common pin to GND (for common cathode).
Connect the red, green, and blue pins to digital PWM pins on the Arduino pins 9, 10, and 11.
Write the Arduino Code
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Show solid Red, Green, and Blue colors one by one
showColor(255, 0, 0); // Red
showColor(0, 255, 0); // Green
showColor(0, 0, 255); // Blue
// Show all color transitions
// Red to Green
smoothTransition(255, 0, 0, 0, 255, 0);
// Green to Blue
smoothTransition(0, 255, 0, 0, 0, 255);
// Blue to Red
smoothTransition(0, 0, 255, 255, 0, 0);
// Red to Yellow
smoothTransition(255, 0, 0, 255, 255, 0);
// Yellow to Cyan
smoothTransition(255, 255, 0, 0, 255, 255);
// Cyan to Magenta
smoothTransition(0, 255, 255, 255, 0, 255);
// Magenta to White
smoothTransition(255, 0, 255, 255, 255, 255);
}
void showColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
delay(1000); // Show each color for 1 second
}
void smoothTransition(int rStart, int gStart, int bStart, int rEnd, int gEnd, int bEnd) {
int steps = 100; // Number of steps for smooth fading
for (int i = 0; i <= steps; i++) {
int redValue = map(i, 0, steps, rStart, rEnd);
int greenValue = map(i, 0, steps, gStart, gEnd);
int blueValue = map(i, 0, steps, bStart, bEnd);
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
delay(20); // Adjust delay for smoother or faster transitions
}
}
Test the Color Output






The RGB LED module will produce smooth transitions between red, green, and blue colors.
The fading effect will be seamless due to the gradual color mixing.
Challenge was finding the optimal delay value for smoothness, which was resolved by setting a 20ms delay per step.
The output created a visually pleasing color gradient.