Color-Changing Mood Light

by dmcits in Circuits > LEDs

8 Views, 0 Favorites, 0 Comments

Color-Changing Mood Light

20250613_145123 (1).jpg

Create a relaxing smart lamp that automatically adjusts brightness based on your room’s light level. As it gets darker, the lamp glows brighter — slowly cycling through calming colors. Perfect for bedrooms, workspaces, or ambient night lights!



Supplies

  1. Arduino Uno
  2. RGB LEDs
  3. 220Ω Resistors
  4. 10KΩ Resistor
  5. LDR (Light Sensor)
  6. Breadboard
  7. Jumper wires
  8. USB Cable
  9. Paper Cube (optional)

Build the LDR Circuit

Screenshot 2025-06-20 at 5.03.58 PM.png

Insert the LDR on the breadboard.

Connect one leg to 5V.

Connect the other leg to A0 on the Arduino.

Add a 10KΩ resistor from that same leg to GND.

Wire RGB LEDs in Pairs

Screenshot 2025-06-20 at 5.05.03 PM.png
20250613_144006 (1).jpg

Group the LEDs into 2 pairs (1 & 2, 3 & 4).

Connect all Red pins in a pair together → resistor → PWM pin.

Repeat for Green and Blue.

Connect all cathodes to GND.

Upload the Code

Open the Arduino IDE.

Paste the code below.

Select your board and port.

Click Upload.

// Light sensor
int ldrPin = A0;

// RGB LED Pair A
int red1Pin = 3;
int green1Pin = 5;
int blue1Pin = 6;

// RGB LED Pair B
int red2Pin = 9;
int green2Pin = 10;
int blue2Pin = 11;

// Color values
int redVal = 255;
int greenVal = 0;
int blueVal = 0;

int fadeSpeed = 5;

void setup() {
pinMode(red1Pin, OUTPUT);
pinMode(green1Pin, OUTPUT);
pinMode(blue1Pin, OUTPUT);
pinMode(red2Pin, OUTPUT);
pinMode(green2Pin, OUTPUT);
pinMode(blue2Pin, OUTPUT);
}

void loop() {
int ldrValue = analogRead(ldrPin);
int brightness = map(ldrValue, 0, 1023, 255, 0); // Invert brightness

int r = map(redVal, 0, 255, 0, brightness);
int g = map(greenVal, 0, 255, 0, brightness);
int b = map(blueVal, 0, 255, 0, brightness);

setColor(r, g, b);
fadeColors();
delay(25); // Smooth transition
}

void setColor(int r, int g, int b) {
analogWrite(red1Pin, r);
analogWrite(green1Pin, g);
analogWrite(blue1Pin, b);

analogWrite(red2Pin, r);
analogWrite(green2Pin, g);
analogWrite(blue2Pin, b);
}

void fadeColors() {
if (redVal > 0 && greenVal < 255 && blueVal == 0) {
redVal -= fadeSpeed;
greenVal += fadeSpeed;
} else if (greenVal > 0 && blueVal < 255 && redVal == 0) {
greenVal -= fadeSpeed;
blueVal += fadeSpeed;
} else if (blueVal > 0 && redVal < 255 && greenVal == 0) {
blueVal -= fadeSpeed;
redVal += fadeSpeed;
}

redVal = constrain(redVal, 0, 255);
greenVal = constrain(greenVal, 0, 255);
blueVal = constrain(blueVal, 0, 255);
}

Downloads

Add a Paper Cube Diffuser (Optional)

20250613_145123 (2).jpg

Print a paper cube template (search “printable cube net”).

Cut and fold into a cube shape.

Leave one face open.

Slide the cube over the LEDs to soften and blend the light.

Downloads