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

IMG20250207173855.jpg

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

IMG20250207174133.jpg

Assemble the Circuit

RGB LED module.png
RGB LED module schem.png

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

Screenshot 2025-02-10 174243.png
Screenshot 2025-02-10 174255.png
Screenshot 2025-02-10 174227.png
RGB LED MOD.gif
Screenshot 2025-02-10 174207.png
Screenshot 2025-02-10 174217.png

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.