Instructables
Picture of Mood Lamp with Arduino
DSCN5319.JPG
DSCN5331.JPG
DSCN5332.JPG
DSCN5333.JPG
DSCN5334.JPG
Hi! In this tutorial you will learn to make a mood lamp with arduino.
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 adsRemove these ads by Signing Up
1-40 of 59Next »
adamantum made it!16 hours ago

Simple and Easy Project. Made in an Hour. Thank You :)

IMG_20141024_225959.jpgIMG_20141024_230029.jpg
adamantum made it!16 hours ago

Simple and Easy Project. Made in an Hour! Thank You "ricadouvina".

IMG_20141024_225959.jpgIMG_20141024_230029.jpg
pious12329 days ago
i made it too .i quite modified the project having more mode of operation plz say me hows it
temp_2036335101.jpgtemp_-1723136447.jpg
agrady19956 months ago
I MADE IT! too bad that button isn't on the iPhone app-- where I'm actually able to upload pics
14, 11:46 PM.jpg14, 11:46 PM.jpg14, 11:46 PM.jpg14, 11:46 PM.jpg
agrady19956 months ago

--Made it in 10 minutes of opening the instructable. It was cool, but it would turn itself off with the LDR as soon as the light came on (I followed the breadboard exactally, and it was close to the LED).

So, about to move it, I took out the LDR, and it worked.... I'll just run it without it. Thank you!

agrady19956 months ago

hi there! I just got my arduino the other day, but i'm kind of quick to learning programming. can you explain the parts of your (equation) that made the lights change the way they did, and how it worked? Thanks!

-- Student and future Biomedical Engineer

Electric_LED made it!7 months ago

Thanks so much!!! I did this quickly and easily!!!

1312043840.jpg
adnafie7 months ago

Hi! thank you for the tutorial. But, i'm have a little problem here. See, i tired to combine this circuit with lm35 temperature sensor so that the circuit can sense temperature and light at the same time. I use different led for different sensor. Now the problem is, when i combine the 2 source code, the mood lamp seems not working well. It lighted up but it dont changing colors. Can you help me with this? Here is my source code:

float RGB[3];

float tempC;

int ldrPin = 0; // LDR in Analog Input 0 to read the ambient light

int analog_tempPin1 = 1;

int ambientLight; // variable to store the value of the ambient light

int ledPin1 = 11; // red LED in Digital Pin 11 (PWM)

int ledPin2 = 10; // green LED in Digital Pin 10 (PWM)

int ledPin3 = 9; // blue LED in Digital Pin 9 (PWM)

int ledPin4 = 7; // LED connected to digital pin 7

int ledPin5 = 6;

void setup(){

pinMode(ledPin1,OUTPUT); // tell arduino it's an output

pinMode(ledPin2,OUTPUT);// tell arduino it's an output

pinMode(ledPin3,OUTPUT); // tell arduino it's an output

// set all the outputs to low

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

pinMode(ledPin4, OUTPUT);

pinMode(ledPin5, OUTPUT);

Serial.begin(9600);

}

void loop(){

for (float x=0;x<PI;x=x+0.00001){

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

ambientLight=analogRead(ldrPin); // read an store the ambient light

if(ambientLight>600){ // start only if the ambient light is very low

// write the brightness on the leds

analogWrite(ledPin1,RGB[0]);

analogWrite(ledPin2,RGB[1]);

analogWrite(ledPin3,RGB[2]);

}

else{

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

}

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);

tempC = analogRead(analog_tempPin1); //read the value from the sensor

tempC = (5.0 * tempC * 100.0)/1024.0; //convert the analog data to temperature

Serial.print("analog ");

Serial.print(analog_tempPin1);

Serial.print(" ");

Serial.println(tempC); //send the data to the computer

if (tempC < 40){

digitalWrite(ledPin4, HIGH); // set the LED on

digitalWrite(ledPin5, LOW); // set the LED off

delay(1000); // wait for a second

digitalWrite(ledPin4, LOW); // set the LED off

digitalWrite(ledPin5, HIGH); // set the LED on

delay(1000); // wait for a second

}

if (tempC > 40){

digitalWrite(ledPin4, HIGH); // set the LED on

digitalWrite(ledPin5, LOW); // set the LED off

delay(100); // wait for 0.1second

digitalWrite(ledPin4, LOW); // set the LED off

digitalWrite(ledPin5, HIGH); // set the LED on

delay(100); // wait for 0.1second

}

}

}

bsüataç9 months ago

Great instructions! I have a problem tough. I managed to make it change lights and everything. However , When it comes to certain colors it flickers with different frequencies. How can I solve this problem? (I have an Arduino UNO and I use a RGB LED)

Solistas9 months ago

For some reason my light sensor doesnt work :(

XxsonicxX1 year ago
While I was buying supplies at radioshack, I accidentally bought the wrong resistors, I bought 1/4 watt 220 ohm resistors instead of the 120k ohm resistors needed... Arduino FAIL
eliara1 year ago
Oi , montei esse projeto , mas o meu só fica piscando em azul os leds o que faço?
ricardouvina (author)  eliara1 year ago
Olá, verifique se todos os caminhos que você montou estão como no esquemático e para garantir baixe o arquivo ZIP ao invés de copiar direto da página. Se ainda não funcionar me avise, ficarei feliz em ajudar. Ah, e você é a primeira brasileira a comentar aqui! =)
d4ng1 year ago
Great Instructable! My first "real" Arduino project.

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?
knobhill1 year ago
I like the project a lot - good work - I want to try putting one together, but if I wanted to modify things so that the leds work under any light (it doesn't have to be pitch black ), how would I go about doing that ?
ricardouvina (author)  knobhill1 year ago
Just remove the following lines:
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.
I have tried of course to use a break inside the for loop, however it does not work!!! I have tried using an outside command via OSC, and also hit a key from the Serial Monitor to break the loop. Nothing works, it looks like it is stuck there - like it waits to finish the whole loop and then exit. But I want to make it happen instantly but so far nothing works! If anyone has a tip, that would be great!
Hi, nice project. I would like to ask you, how is it possible to escape the for loop? I want to use this as a feature in my project against other features (i.e. Mode 1 - All lights off, Mode 2 - All lights on, Mode 3 - Mood Lights). Using a control I want to go from one mode to the other, however, when I use this for loop everything gets stuck as it is a very long loop and takes for ever to complete. What do you suggest?

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
}
ricardouvina (author)  louisbourdon1 year ago
What you can do is use a "break" inside the "if" loop to stop it, but use it carefully, otherwise it can be very harmful.
pabhilash1 year ago
Hello again! never mind, it's working fine now! i misplaced a wire :P thanks so much! may i suggest something? when you define the ambient light settings, you should try changing it to 900 instead of 700. under 700, the LED's glow even in a fairly lit room! :)
ricardouvina (author)  pabhilash1 year ago
OK! That value is up to you. You choose what better works to you!
pabhilash1 year ago
Hello! great I'ble! There seems to be a small problem- uploading gets done fine, but immediately the LED(RGB) just glows light blue,even in a well lit area! and the color does not change! could you please help?(it's an Uno by the way..)
ricardouvina (author)  pabhilash1 year ago
Did you download the zip file, or did you copy the code from the step and paste it on arduino's program?
sarah911 year ago
What do I change when it is 1 red LED, 1 green LED and 1 yellow LED?
ricardouvina (author)  sarah911 year ago
Nothing. You will just get different colors than mine.
geoffb372 years ago
hi
me again, how can i get it to cycle thru green/ it does blue thru red/orange/purple but not green?
Vertec2 years ago
Hi , I really like your project , I was trying to build it , and i am stuck in a situation that i am using RGB LED , (one that you have shown in your project also first image) but I have common anode , it change the light effect exactly as you describe in your project , but my LDR is not working , means its not light sensitive,
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
Vertec Vertec2 years ago
Hi , Thanks for your reply can you please tell me the value of the resistor you have used for it , or the minimum value of the resistor i can use with the LDR? (it must be start with 10k at least) if i am not wrong !
ricardouvina (author)  Vertec2 years ago
I used a 120k resistor, but anything between 10k and 1M should work just fine, but remember to adjust the ambient light threshold as I said before.
I hope you can make it! :)
ricardouvina (author)  Vertec2 years ago
Hi.
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.
Ozzie_G2 years ago
Nice little project, Thanks

What exactly are you trying to achieve with the delays depending on the current brightness of all three channels?

ricardouvina (author)  Ozzie_G2 years ago
Hi!
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!
My RGB LED has the second lead as positive, and all the colors as negative. So when I wire it as described, with the long terminal on the LED hooked to ground, nothing happens. When I move that wire to the positive (5V), it lights up, but constantly and all colors are on.
Any ideas how to get it working?
Ok, I switched the positive and negative wires on the arduino, and now it rotates through the colors, however it does it all the time, the photosensor doesnt seem to turn it off. I tried switching the negative/positive orientation on it, but no change.

Also, how would you make it fade through the whole spectrum of light?
ricardouvina (author)  ponynicker532 years ago
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.

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.
kartikrv2 years ago
Hey!

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!
ricardouvina (author)  kartikrv2 years ago
Hi!
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!
xiaojiang2 years ago
So nice ! I was going to use it for my good friend.
ricardouvina (author)  xiaojiang2 years ago
I hope he likes!
geoffb372 years ago
Excellent first project for myself with the limited things that came with my uno kit.
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.
1-40 of 59Next »