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 pour Serial port // start serial pour sortie pour testing
}

void loop()
{
//
read l' value à partir de l' ldr:
sensorValue
= analogRead(sensorPin);

if(sensorValue>400){ // set l' LED OFF // lower number pour on when darker ou raise number pour 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 l' lines below
//Serial.print(sensorValue,
DEC); // print l' value (0 pour 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


A Propos De L'Auteur

Ibrar Ayyub

Je suis expérimenté, rédacteur technique, titulaire d'une Maîtrise en informatique de BZU Multan, Pakistan à l'Université. Avec un arrière-plan couvrant diverses industries, notamment en matière de domotique et de l'ingénierie, j'ai perfectionné mes compétences dans la rédaction claire et concise du contenu. Compétent en tirant parti de l'infographie et des diagrammes, je m'efforce de simplifier des concepts complexes pour les lecteurs. Ma force réside dans une recherche approfondie et de présenter l'information de façon structurée et logique format.

Suivez-Nous:
LinkedinTwitter

Laisser un Commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench
Faire défiler vers le Haut