Color Changing Night Light with ATtiny using Arduino

Arduino Color Changing Night Light (3)

I wanted to create something for my wife as a present and this is what I came up with. This is a dark activated color changing night light. It has a sensor that can tell when the room light is turned off. This then will light a RGB LED and slowly fade through different colors. Its brains is a ATtiny85, but you could also use an Arduino.  We have little boys that would appreciate this on at night.

Arduino Color Changing Night Light (3)

Step 1: Parts

Parts for the Circuit:

  • 22uf capacitor
  • 10nf 103” capacitor
  • 7805 voltage regulator
  • LDR  (Light Dependent Resistor)
  • 2 – 10K resistor
  • 2 – 100ohm resistor
  • 220ohm resistor
  • RGB LED (The one I got from RadioShack has a common anode.)
  • ATtiny85 (can be bought at www.sparkfun.com)
  • 8 pin socket
  • Wire
  • Perfboard
  • Wall Wort Plug about 7-18V (test this with a voltmeter, don’t trust the label)

Everything can bought at RadioShack but the ATtiny85.

Don’t buy the Wall Wort Plug. You or someone you know probably has one they don’t use, like the plug to charge a cell phone… When possible, recycle.

Parts for the Light:

  • Hobby Glass Block
  • Hot Glue Gun
  • Glass Block Stand
  • Glass Frosting Spray Paint
  • Paint Pen/Sharpie

Other Items:

  • Computer
  • Arduino
  • Breadboard
  • Jumper Wire
  • Wire Stripper
  • Voltmeter
  • Soldering Iron
  • Solder
  • Razer Blade

Assumptions:

  • That you at least have a little experience programing an Arduino and know how to solder on a perfboard.  If you are an absolute beginner you may need some help.

Step 2: Programing

There are many great sites and other instructables that give step by step instructions on how to program a ATtiny85 with a Arduino. You could just use the Arduino instead of the ATtiny85 if you like.  You would just have to change the pin locations in the code. The reason I used the ATtiny85 was because it is a cheap chip and I wanted the smaller form factor. The ATtiny85 can be programed on a shield if you have one or right on a breadboard.

Check out:

 

Here is the sketch/program:Arduino Color Changing Night Light circuit (3)

// attiny85 RGB LED rainbow fade with LDR

//By Matt Jenkins

const int redPin = 2;

const int grnPin = 4;

const int bluPin = 1;

int sensorPin = 3; // select the input pin for the ldr

unsigned int sensorValue = 0; // variable to store the value coming from the ldr

void setup()
{
pinMode(redPin,
 OUTPUT);
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);

//Start Serial port
//Serial.begin(9600); // uncomment for Serial port // start serial for output  for testing
}

void loop()
{
//
 read the value from the ldr:
sensorValue
 = analogRead(sensorPin);

if(sensorValue>400){ // set the LED OFF // lower number for on when darker or raise number for on when brighter
digitalWrite(redPin,
 HIGH);
digitalWrite(grnPin,
 HIGH);
digitalWrite(bluPin,
 HIGH);
}

else{ //Fade through Colors
redtoyellow();
yellowtogreen();
greentocyan();
cyantoblue();
bluetomajenta();
majenatored();
}
delay
 (30);

// For DEBUGGING  Print out our data, uncomment the lines below
//Serial.print(sensorValue,
 DEC); // print the value (0 to 1024)
//Serial.println(“”);

//delay(500);
}

void redtoyellow()
{
digitalWrite(redPin,
 HIGH);
digitalWrite(bluPin,
 LOW);
//
 fade up green
for(byte
 i=1; i<100; i++) {
byte
 on = i;
byte
 off = 100-on;
for(
 byte a=0; a<100; a++ ) {
digitalWrite(grnPin,
 HIGH);
delayMicroseconds(on);
digitalWrite(grnPin,
 LOW);
delayMicroseconds(off);
}
}

}

void yellowtogreen()
{

digitalWrite(grnPin, HIGH);
digitalWrite(bluPin, LOW);
// fade down red
for(byte i=1; i<100; i++) {
byte on = 100-i;
byte off = i;
for( byte a=0; a<100; a++ ) {
digitalWrite(redPin, HIGH);
delayMicroseconds(on);
digitalWrite(redPin, LOW);
delayMicroseconds(off);
}
}
}

Step 3: Breadboard and Test

Now that your ATtiny85 is programed, I will describe how to make this circuit on a breadboard. You can view the pictures for clarification.

  •  You will notice that there is a small notch in one end on the top of the ATtiny85. The notch indicates the front. I will refer to the pins by number. And they are numbered like so. To the left of the notch is pin 1, and down the chip 2, 3, 4. Accost the chip and up back toward the notch is 5, 6, 7, 8.  (see pic)
  •  You can use jumper wire to connect all the parts.
  •  You are going to use the Arduino to power the breadboard along the sides so you will have a row to 5v and row of ground, but don’t do it yet.
  •  Pin 1 is the reset and connects to ether side of the 10K resistor then the resistor goes to 5v.  (doing this is called a pull-up resistor)

Read more: Color Changing Night Light with ATtiny using Arduino

Leave a Comment

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