ATtiny85 Mini RGB Mood Light!
ATtiny85 Mini RGB Mood Light!
ATtiny85 Mini RGB Mood Light!
ATtiny85 Mini RGB Mood Light!
ATtiny85 Mini RGB Mood Light!
I have seen RGB mood lights using Arduino, PIC, and larger AVR chips, but never one with the ATtiny85. That's why I decided to make one.

This mood light is super simple to make and all the parts can be purchased online for about $5.00 total (not including the Arduino used to program the chip).

This is a contest entry in the LED contest with Elemental LED and the Hurricane Lasers contest, so if you like it, vote!

EDIT: I have changed this instructable so that it is a NIGHT LED Mood Lamp. It now only lights up when the ambient light in the room is very low (at night with all the lights off). You do need an LDR and a 10K ohm resistor to add this part though. If you want it to not have this feature, just remove the LDR/10K resistor part and connect Analog Input 3 of the ATtiny (pin 2) straight to ground.

Step 1: How does it work?

The ATtiny85 only has 2 PWM pins, so obviously you can't make all 3 colors of the RGB LED fade in and out smoothly, right? Wrong.

The way I got around this was by using software PWM. This means that I can fade in and out of all 3 colors using any of the pins on the ATtiny.

How software PWM works is by setting the pin HIGH and then LOW at different rates so that the LED looks like it's dimming. This is called Persistence of Vision or POV (for more on POV, see my instructable here). The LED blinks so rapidly that the human eye can't detect that it is flashing at all, and it sees instead that the LED appears to be dimming.

Step 2: Parts list

ATtiny85 Mini RGB Mood Light!
You will need:

1x Common cathode RGB LED
3x 220 ohm resistors
1x ATtiny85 Microcontroller

For the Light sensing part:

1x LDR (light dependent resistor)
1x 10K ohm resistor

And to program the ATtiny:

1x Arduino Uno or equivalent
1x A to B USB cable for Arduino

Step 3: Program the chip

ATtiny85 Mini RGB Mood Light!
Go here and it will show you how to connect the ATtiny85 to the Arduino and program it. Once you are ready to upload the code to the ATtiny85, paste it into the Arduino IDE and click upload.



//ATtiny85 RGB color fading Mood Light NOW WITH LIGHT SENSING CAPABILITIES!!!

const int redPin = 2;
const int grnPin = 1;
const int bluPin = 0;
const int sensor = 3;


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

void loop() {
if (analogRead(sensor) {
redtoyellow();
yellowtogreen();
greentocyan();
cyantoblue();
bluetomagenta();
magentatored();
}
else if (analogRead(sensor) >= 201)
{
digitalWrite(redPin, LOW);
digitalWrite(grnPin, LOW);
digitalWrite(bluPin, LOW);
}
}

void redtoyellow()
{
digitalWrite(redPin, HIGH);
digitalWrite(bluPin, LOW);

// fade up green
for(byte i=1; i byte on = i;
byte off = 100-on;
for( byte a=0; 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 byte on = 100-i;
byte off = i;
for( byte a=0; a digitalWrite(redPin, HIGH);
delayMicroseconds(on);
digitalWrite(redPin, LOW);
delayMicroseconds(off);
}
}
}


void greentocyan()
{
digitalWrite(grnPin, HIGH);
digitalWrite(redPin, LOW);

// fade up blue
for(byte i=1; i byte on = i;
byte off = 100-on;
for( byte a=0; a digitalWrite(bluPin, HIGH);
delayMicroseconds(on);
digitalWrite(bluPin, LOW);
delayMicroseconds(off);
}
}
}



void cyantoblue()
{
digitalWrite(bluPin, HIGH);
digitalWrite(redPin, LOW);

// fade down green
for(byte i=1; i byte on = 100-i;
byte off = i;
for( byte a=0; a digitalWrite(grnPin, HIGH);
delayMicroseconds(on);
digitalWrite(grnPin, LOW);
delayMicroseconds(off);
}
}
}


void bluetomagenta()
{
digitalWrite(bluPin, HIGH);
digitalWrite(grnPin, LOW);

// fade up red
for(byte i=1; i byte on = i;
byte off = 100-on;
for( byte a=0; a digitalWrite(redPin, HIGH);
delayMicroseconds(on);
digitalWrite(redPin, LOW);
delayMicroseconds(off);
}
}
}



void magentatored()
{
digitalWrite(redPin, HIGH);
digitalWrite(grnPin, LOW);

// fade down blue
for(byte i=1; i byte on = 100-i;
byte off = i;
for( byte a=0; a digitalWrite(bluPin, HIGH);
delayMicroseconds(on);
digitalWrite(bluPin, LOW);
delayMicroseconds(off);
}
}
}

Step 4: Connect it

ATtiny85 Mini RGB Mood Light!
Connect the ATtiny to the LEDs and 3V like shown in the schematic, and that's it!

If you want the circuit to not respond to light and be constantly on and fading, just remove the LDR and 10K resistor and connect Analog Input 3 (pin 2) straight to ground.

Step 5: You're done!

Good Job! When you apply 3 volts it should start to fade through the different colors.
 
 

Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel