Color Changing Nightlight using Arduino

So, instead of buying a nightlight for my kid’s room, I decided I could do a much better job of it. This nightlight cycles through 1500 colors over 7 mins and turns on when it is dark and turns off when it is light. It is also small enough into small objects to add effect.

Step 1: Setup Arduino

Arduino Color Changing Nightlight

First create a voltage divider with the photoresistor and the 10k resistor. You can choose any ADC pin, I used 20. I also connected the photoresistor to VCC and 10k to ground. If you choose to swap those, it will change your threshold values and inequalities in your if statements. You can see the configuration in the picture. I didn’t install current restricting resistors on the RGB LED because this microcontroller doesn’t source much current, but if you may not be that lucky, read the spec sheet for the LED to see current values. The reason I’m crossing the board with the resistor and LED is because many of the grounds on this board were not working.

Step 2: Programming

Here is the program if used, you may have to changes sometimes to adapt it to your microcontroller.

/*
NightLight
*/

int sensorValue = 0;  // Variable to store the value coming from the photoresistor
int ledPin1 = 0; // Connect an LED to PWM pin 0
int ledPin2 = 1;        // '' pin 1
int ledPin3 = 2; // '' pin 2
int fadeValue2 = 0; // Variable for fading 2 colors at once
int threshold = 850; // Threshold value for the photoresistor
void lightup(void);

void setup() {
pinMode(20, INPUT_ANALOG); // Setup pin 20 to read a voltage
pinMode(ledPin1, PWM);   // setup the pin as PWM
pinMode(ledPin2, PWM);
pinMode(ledPin3, PWM);
}
Major Components in Project
Items needed are:

Arduino Microcontroller or equivalent                          (used a Mapleleaf for this)
RBG HB LED common cathode                                   (this one is COM-09264 from sparkfun.com)
Photoresistor                                                                    (this one is from Radioshack, any will do)
10k ohm Resistor

For more detail: Color Changing Nightlight using Arduino


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top