Summary of Color Changing Nightlight using Arduino
This project creates a color-changing nightlight for a child's room using an Arduino microcontroller. The nightlight cycles through 1500 colors over 7 minutes and automatically turns on in the dark and off in the light via a photoresistor sensor. The setup involves creating a voltage divider with a photoresistor and a 10k resistor, and programming the Arduino to control a common cathode RGB LED without current-limiting resistors. The design is compact and customizable to fit into small objects for aesthetic effect.
Parts used in the Color Changing Nightlight using Arduino:
- Arduino Microcontroller or equivalent (Mapleleaf used)
- RGB HB LED common cathode (COM-09264 from sparkfun.com)
- Photoresistor (any standard photoresistor, Radioshack recommended)
- 10k ohm Resistor
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
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); }
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