I know that you may have seen a lot of mood lamp projects with arduino, but I wasn't very satisfied with them because they all change the color very abruptly. So, I decided to make a smooth mood lamp and I also made it to turn on only when the room is dark.
This project is good for those who are beginners in the arduino's world.
Remove these ads by
Signing UpStep 1: Material
- Arduino
- Jumper wires
- 1 RGB LED or 1 red LED, 1 green LED and 1 blue LED
- LDR (Light Dependent Resistor)
- Protoboard
- Sheet of paper







































Visit Our Store »
Go Pro Today »




I am attempting to change/add the colors the my RGB LED cycles through.
I have attempted several things but am hitting a dead end..any ideas?
if(ambientLight>600){ // start only if the ambient light is very low
// write the brightness on the leds
analogWrite(redLed,RGB[0]);
analogWrite(greenLed,RGB[1]);
analogWrite(blueLed,RGB[2]);
}
else{
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
digitalWrite(blueLed,LOW);
}
and substitute them by:
analogWrite(redLed,RGB[0]);
analogWrite(greenLed,RGB[1]);
analogWrite(blueLed,RGB[2]);
without the if loop.
I haven't tried this but I think this should work.
for (float x=0;x RGB[0]=255*abs(sin(x*(180/PI))); // calculate the brightness for the red led
RGB[1]=255*abs(sin((x+PI/3)*(180/PI))); // calculate the brightness for the green led
RGB[2]=255*abs(sin((x+(2*PI)/3)*(180/PI)));// calculate the brightness for the blue led
}
me again, how can i get it to cycle thru green/ it does blue thru red/orange/purple but not green?
1) For the common anode RGB LED , only the polarity of the wires will be change (if i follow your design) ? or any thin else
I hope you can make it! :)
Yes, for the common anode RGB LED only the polarity changes, you must be having trouble with the LDR due to the value of the resistor that you're using with it, try to change the ambient light threshold, try to adjust the code at:
if(ambientLight>600){ // start only if the ambient light is very low
change the number 600 to a value that works for you, try to increase or decrease it.
What exactly are you trying to achieve with the delays depending on the current brightness of all three channels?
Show all the colors in a long period of time, otherwise the red, blue and green colors would be on for a very short period of time, and it would change very quickly and I wanted it to be very smooth.
Thanks for your comment!
Any ideas how to get it working?
Also, how would you make it fade through the whole spectrum of light?
if(ambientLight>600){ // start only if the ambient light is very low
change the number 600 to a value that works for you, try to increase or decrease it.
About the spectrum of light, I'm sorry but I don't know how to make. Try to search on the web, probably there is some kind of sine function that does that.
First of all, this is a pretty sweet project. I'm just getting myself used to some pre-done projects before jumping into my own stuff.
My question: how would the circuit change if you dont have an ldr?
Thanks!
It's very simple, just remove the "if" function and the ambientLight variable, like this:
float RGB[3];
int redLed = 11; // red LED in Digital Pin 11 (PWM)
int greenLed = 10; // green LED in Digital Pin 10 (PWM)
int blueLed = 9; // blue LED in Digital Pin 9 (PWM)
void setup(){
pinMode(redLed,OUTPUT); // tell arduino it's an output
pinMode(greenLed,OUTPUT);// tell arduino it's an output
pinMode(blueLed,OUTPUT); // tell arduino it's an output
// set all the outputs to low
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
digitalWrite(blueLed,LOW);
}
void loop(){
for (float x=0;x RGB[0]=255*abs(sin(x*(180/PI))); // calculate the brightness for the red led
RGB[1]=255*abs(sin((x+PI/3)*(180/PI))); // calculate the brightness for the green led
RGB[2]=255*abs(sin((x+(2*PI)/3)*(180/PI)));// calculate the brightness for the blue led
// write the brightness on the leds
analogWrite(redLed,RGB[0]);
analogWrite(greenLed,RGB[1]);
analogWrite(blueLed,RGB[2]);
for(int i=0;i<3;i++){
if(RGB[i]<1){
delay(100);
}
if(RGB[i]<5){
delay(50);
}
if(RGB[i]<10){
delay(10);
}
if(RGB[i]<100){
delay(5);
}
}
delay(1);
}
}
I hope it helps, thank for the comment!
How do you think we could say put a strobe effect in there via a switch?
Many thanks for the post !!
On all the time as i havent found near a 120K resistor yet lol.
It would be something like that:
if(switch = ON){
strobe();
}
else{
moodLamp();
}
About the resistor, any other near value should work, you just have to adjust the value of the ambient light.
I hope you can do it and make an instructable.
Nice job!