Color Changing Night Light with ATtiny using Arduino

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

Step 1: Parts

Parts for the Circuit:

  • 22uf capacitor
  • 10nf 103capacitor
  • 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

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

Major Components in Project
  • Computer
  • Arduino
  • Breadboard
  • 220ohm resistor
  • RGB LED
  • ATtiny85

 

For more detail: Color Changing Night Light with ATtiny 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