This Remote Control Easter Egg Has 16,581,375 Colors.
by kendrickgoss in Circuits > LEDs
19637 Views, 73 Favorites, 0 Comments
This Remote Control Easter Egg Has 16,581,375 Colors.
This Easter egg has 16,581,375 colors. The color can be changed using any button on any TV, DVD, or VCR remote. It fills me with delight.
This project uses an RGB LED to produce colors inside a white egg. The brain of the random selection is an ATMEL Attiny85 microcontroller programmed with an Arduino board. The part that communicates with the remote controls is a phototransistor sensitive to the wavelength of light and modulation (carrier frequency) of the remote.
This project uses an RGB LED to produce colors inside a white egg. The brain of the random selection is an ATMEL Attiny85 microcontroller programmed with an Arduino board. The part that communicates with the remote controls is a phototransistor sensitive to the wavelength of light and modulation (carrier frequency) of the remote.
Getting What You Will Need:
1 Attiny85 (or 45) microcontroller (digikey #ATTINY85V-20PU-ND )
1 common anode RGB LED (I got mine from adafruit.com (#159))
3 220 ohm 1/4 watt resistors
1 Infrared (IR) phototransistor (you can order one from adafruit.com (#157) or salvage one.)
3 or 4 1.4 volt batteries (I got these at the drugstore (for hearing aids))
The IR phototransisitor that I used in this project came from the front panel of a lifeless VCR. If you are ordering other parts, it is cheap to buy a new one ($2?), but I actually do get a kick out of digging as many parts as I can out of old machines.
The resistors only serve to limit current to the LED, so anything from 180 to 560 would really be OK, just use 3 of the same value.
If the RGB LEDs you find are common cathode, connect the common pin to ground, obviously, but I think the code will still work, just producing the chromatic compliment of whatever you would get from a common anode part. I think.
For this circuit, I stacked up 4 little batteries and got about 5.4 volts. In the past, I have run projects using the Attiny85 and RGB LEDs with a 3 volt coin cell (CR2032 type), but the IR transistor in this project seems to really want 5 volts to run properly.
1 common anode RGB LED (I got mine from adafruit.com (#159))
3 220 ohm 1/4 watt resistors
1 Infrared (IR) phototransistor (you can order one from adafruit.com (#157) or salvage one.)
3 or 4 1.4 volt batteries (I got these at the drugstore (for hearing aids))
The IR phototransisitor that I used in this project came from the front panel of a lifeless VCR. If you are ordering other parts, it is cheap to buy a new one ($2?), but I actually do get a kick out of digging as many parts as I can out of old machines.
The resistors only serve to limit current to the LED, so anything from 180 to 560 would really be OK, just use 3 of the same value.
If the RGB LEDs you find are common cathode, connect the common pin to ground, obviously, but I think the code will still work, just producing the chromatic compliment of whatever you would get from a common anode part. I think.
For this circuit, I stacked up 4 little batteries and got about 5.4 volts. In the past, I have run projects using the Attiny85 and RGB LEDs with a 3 volt coin cell (CR2032 type), but the IR transistor in this project seems to really want 5 volts to run properly.
Programming the Microcontroller.
I used the code and method from the MIT high/low tech blog (http://hlt.media.mit.edu/?p=1706) to turn my Arduino into an Attiny programmer and upload programs to an Attiny85 microcontroller chip. I used the Attiny chip because it is smaller than the Arduino Atmega 328 chip (so it will fit into a chicken egg) and it is so inexpensive ($1.30) I did not feel bad about having it being a single use part.
I put together a programming shield with perf-board just to streamline things, but you can do all of this programming with a breadboard and wire leads. Follow the directions from the MIT site to add the ArduinoISP sketch to your Arduino IDE. Once that is downloaded and installed:
1. Plug your Arduino board into your computer and upload the ArduinoISP sketch from the Examples menu.
2. Use your breadboard and leads or ISP shield to connect the Attiny chip to the Arduino.
3. Open a new window in the Arduino IDE and paste the RemoteEgg sketch (below).
4. Save the sketch.
5. From the IDE menu, select Tools>Board>"Attiny85(w/Arduino as ISP)"
6. Upload the sketch. (This time, the upload will go to the Attiny.)
-----------------------------------------------------------------------------------------------------------------
// This is the RemoteEgg program intended for use with an
// Attiny85 microcontroller. by Kendrick Goss
// This program is in the public domain.
// This sketch waits for an IR pulse from a remote control
// and then randomly changes the color of an RGB LED
int ledPinRED = 2; // LED on digital pin 2
int ledPinGREEN = 1; // LED on digital pin 1
int ledPinBLUE = 4; // LED on digital pin 0
int inPin = 0; // the input pin for the IR phototransistor
int randRED = 0;
int randGREEN = 0;
int randBLUE = 0;
void setup() {
pinMode(inPin, INPUT); // declare IR phototransistor as input
}
void loop(){
while(digitalRead(inPin) != LOW) {}; // read input value
randRED = random(255); // picking a random number
randGREEN = random(255); // between 1 and 255
randBLUE = random(255);
analogWrite(ledPinRED, randRED);
analogWrite(ledPinGREEN, randGREEN);
analogWrite(ledPinBLUE, randBLUE);
delay(100); // de-bounces the input so it does not zoom
// through a zillion colors with every button click
}
I put together a programming shield with perf-board just to streamline things, but you can do all of this programming with a breadboard and wire leads. Follow the directions from the MIT site to add the ArduinoISP sketch to your Arduino IDE. Once that is downloaded and installed:
1. Plug your Arduino board into your computer and upload the ArduinoISP sketch from the Examples menu.
2. Use your breadboard and leads or ISP shield to connect the Attiny chip to the Arduino.
3. Open a new window in the Arduino IDE and paste the RemoteEgg sketch (below).
4. Save the sketch.
5. From the IDE menu, select Tools>Board>"Attiny85(w/Arduino as ISP)"
6. Upload the sketch. (This time, the upload will go to the Attiny.)
-----------------------------------------------------------------------------------------------------------------
// This is the RemoteEgg program intended for use with an
// Attiny85 microcontroller. by Kendrick Goss
// This program is in the public domain.
// This sketch waits for an IR pulse from a remote control
// and then randomly changes the color of an RGB LED
int ledPinRED = 2; // LED on digital pin 2
int ledPinGREEN = 1; // LED on digital pin 1
int ledPinBLUE = 4; // LED on digital pin 0
int inPin = 0; // the input pin for the IR phototransistor
int randRED = 0;
int randGREEN = 0;
int randBLUE = 0;
void setup() {
pinMode(inPin, INPUT); // declare IR phototransistor as input
}
void loop(){
while(digitalRead(inPin) != LOW) {}; // read input value
randRED = random(255); // picking a random number
randGREEN = random(255); // between 1 and 255
randBLUE = random(255);
analogWrite(ledPinRED, randRED);
analogWrite(ledPinGREEN, randGREEN);
analogWrite(ledPinBLUE, randBLUE);
delay(100); // de-bounces the input so it does not zoom
// through a zillion colors with every button click
}
The Circuit.
Plug the Attiny and the other parts into the breadboard and supply 5 volts. Keep in mind that the pin number on the chip (counted 1 through 8 counterclockwise from the top of the chip) do not match up to the pin numbers in the program code. See the diagram for set up. It is important to check the circuit out on the breadboard first - just to make sure the program uploaded and to make sure you like the way it works.
The circuit should be responsive to a remote control click. The way this works is that the IR phototransistor is actually tuned to watch for pulses of light flashing at 38kHz. This is the frequency remotes use and makes the whole system remarkably sensitive, even through the egg shell. (For more information on this, see ladyada's write up here: http://www.ladyada.net/learn/sensors/ir.html) We are not actually de-coding any of the pulses here - all the button pushes mean the same thing to this circuit ("Go!"). The phototransistor is powered by the batteries and outputs power to the OUT pin when it detects the remote flashing at 38 KHz. While the pin connected Attiny has no volts (is LOW), it does nothing. When it goes HIGH (power delivered), it cues the Attiny to change the color of the LED.
The circuit should be responsive to a remote control click. The way this works is that the IR phototransistor is actually tuned to watch for pulses of light flashing at 38kHz. This is the frequency remotes use and makes the whole system remarkably sensitive, even through the egg shell. (For more information on this, see ladyada's write up here: http://www.ladyada.net/learn/sensors/ir.html) We are not actually de-coding any of the pulses here - all the button pushes mean the same thing to this circuit ("Go!"). The phototransistor is powered by the batteries and outputs power to the OUT pin when it detects the remote flashing at 38 KHz. While the pin connected Attiny has no volts (is LOW), it does nothing. When it goes HIGH (power delivered), it cues the Attiny to change the color of the LED.
Solder It Together in Some Sort of Tall and Compact Shape.
This construction method is sometimes referred to as "dead bug" because, of course, the Attiny appears to be done in, on its back with its feet up in the air. PAY SPECIAL attention, when soldering something together like this, that you get the pin numbers right - they are backwards when the chip is upside down.
Don't rush it, keep in mind the parts are heat sensitive, AND breath a sigh of relief at the end to see that it all still works!
Don't rush it, keep in mind the parts are heat sensitive, AND breath a sigh of relief at the end to see that it all still works!
Empty the Egg
Poke a hole in the bottom of a white egg. Shake it until the insides come out. Oh, and: do this over a sink. Widen the hole with scissors to fit the light assembly.
To give the whole assembly some weight and a place to stand, I soldered a short piece of copper pipe onto a penny. The stacked up batteries (wrapped up with tape) are inside the tube,
To give the whole assembly some weight and a place to stand, I soldered a short piece of copper pipe onto a penny. The stacked up batteries (wrapped up with tape) are inside the tube,
Assemble It and Click Through the Colors.
Leaving this by the TV is fun, for a while. Happy Easter!