Introduction: Colour Changing LED Night Light
I hadn't done a single electronics project for a month, and seeing my Arduino after so long made me pretty excited, albeit a little lost. I felt I needed a small, simple project to revive my familiarity with Arduino. This RGB LED night light was good enough for the purpose; I had all components in my drawers and it didn't take too much time to make. It's easy to make, and suitable for one beginning to work with wires and solder.
Although it took less than a couple of hours to finish, this night light ispretty good-looking, especially in the dark. In fact, it benefits my younger sister, who is delighted having this lamp to illuminate her bedroom at night.
In this instructable, I'll be showing you how I made my RGB LED Night Light with an ATtiny13 at its heart. Of course, this isn't a strict guide; you can use your imagination and modify the design of the lamp, change the LED driver code, or even use a totally different circuit!
Step 1: Project Details and Materials...
Cost: $8
Time Required: 2 hours
Difficulty: Easy
Skills Required:
- Basic Knowledge of Electronics
- Some experience with Arduino and Porgramming
- Experience with soldering
Materials:
- ATtiny13 or ATtiny45 or ATtiny85 microcontroller
- RGB LED strip (1.5 - 2m)
- 240V to 12V transformer (OR a 120V to 12V one if you live in the states)
- 7805 regulator IC
- IN4007 diodes (5 of them)
- 2N2222 transistors (2-3 of them)
- 1K resistors x2
- Capacitors:- 1000uF, 10uF
- Jumper wires
- 8pin IC socket or Berf Socket
- General PCB
- White paper
- Cardboard tube
Step 2: Make the RGB LED Controller Circuit...
The RGB LED controller has an ATtiny microcontroller at it's heart. It produces a PWM signal that is used to vary the brightness of the red, green and blue LEDs. I used an ATtiny13, because that's what I had at the moment. Don't worry though; you can use an ATtiny45 or ATtiny85 too, and they are pin compatible!
The circuit is shown in the diagram above.
Step 3: Connect the RGB LED Strip...
All that's remaining in the circuit is the RGB LED Strip. In my case I've got a common anode strip, so the "common" wire (usually red or white) must be connected to +12V.
Unfortunately the ATtiny13 only has 2 PWM outputs, so I can control only 2 colours of LEDs at once. So I decided to connect RED to Ground permanently. This means the red LEDs will remain on all the time, so you'd get more of the warmer colours like yellow and pink. If you want cooler colours, connect green or blue to ground instead.
The GREEN and BLUE wires of the LED strip are connected to the collectors of each transistor on the controller. See the diagram and picture above for details.
Step 4: Connect the ATtiny to Arduino (For Programming)...
Follow the Fritzing diagram above to connect the ATtiny13 to an Arduino. This is the setup for uploading the bootloader and our code to the ATtiny13 chip. (Works with the ATtiny25/45/85 chips too)....
Step 5: Program the ATtiny Chip...
You will need an Arduino board to program the ATtiny chip. Here I'm only going to show you how to program an ATtiny13. For programming other chips, see below:
- ATtiny45
- ATtiny85
- ATtiny2313 (This chip has an entirely different pinout)
Now, follow these instructions to program the ATtiny13:
- Download the ATtiny13 cores from here
- Go to the "sketchbook" directory of Arduino. It's usually Documents < Arduino. Make a folder named "hardware".
- Unzip the contents of the downloaded file to this folder. You should see this folder structure:
~Arduino/hardware/tiny/
- In the tiny folder, there should be a boards.txt file. Right click and select edit. (If there's no such file create one)
- Paste the following into the file (removing what was there earlier):
########################################################################### attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator) attiny13.upload.using=arduino:arduinoisp attiny13.upload.maximum_size=1024 attiny13.upload.speed=250 attiny13.bootloader.low_fuses=0x68 attiny13.bootloader.high_fuses=0xFF attiny13.build.mcu=attiny13 attiny13.build.f_cpu=128000 attiny13.build.core=core13 ############################################################### attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock) attiny13at4.upload.using=arduino:arduinoisp attiny13at4.bootloader.low_fuses=0x69 attiny13at4.bootloader.high_fuses=0xff attiny13at4.upload.maximum_size=1024 attiny13at4.upload.speed=9600 attiny13at4.build.mcu=attiny13 attiny13at4.build.f_cpu=600000 attiny13at4.build.core=core13 ############################################################### attiny13at9.name=ATtiny13 @ 9.6MHz (internal 9.6 MHz clock) attiny13at9.bootloader.low_fuses=0x7a attiny13at9.bootloader.high_fuses=0xff attiny13at9.upload.maximum_size=1024 attiny13at9.build.mcu=attiny13 attiny13at9.build.f_cpu=1200000 attiny13at9.build.core=core13
- Now open the Arduino IDE and go the file < examples < ArduinoISP, and upload that code to your Arduino board.
- Now connect your Arduino to the ATtiny using the fritzing diagrams above. Note that theres a different circuit for the Non-MEGA and MEGA boards.
Now start the Arduino IDE. Go to tools < boards, and you should see the ATtiny13 somewhere. Select "ATtiny13 9.6MHz"
Then, in tools < programmer, select "ArduinoISP". Then select burn bootloader.
After that's done, copy this code to the Arduino window:
byte x; void setup(){ pinMode(3, OUTPUT); pinMode(0, OUTPUT); pinMode(1, OUTPUT); } void loop(){ analogWrite(0, x); analogWrite(1, x+128); digitalWrite(3, HIGH); x = x+20; delay(600); }
- Now go to file < upload using programmer. The Arduino should convey the program to the ATtiny.
- Put the ATtiny into the IC socket on the controller board: correctly, or the chip will blow.
Step 6: Make the Transformer and Rectifier Circuit...
The transformer converts high voltage mains AC to 12V AC. However, we need DC12V for our circuit, so I made a rectifier circuit for the task. The rectifier is a small circuit that converts an AC signal into DC and smoothens out the "pulse". See the schematic above for the circuit. I've also included pictures of my circuit in the making to give you an idea of the layout of the components on the PCB.
Note: Soldering required, keep your workshop well ventilated!
Step 7: Prepare the Transformer...
We need to connect the high voltage input of the transformer to a male wall plug. Do so with solder (to be on the safe side) and insulation tape, as shown above.
Step 8: Prepare a Case for the Tranformer...
You'd obviously want to keep high voltage AC circuits insulated, right? Not to mention to hide all the wires and mess. So I used a small plastic box (like the one above) to the job. Make holes for the wire if necessary.
Step 9: Prepare the Cardboard Tube...
I cut a cardboard tube (from a paper roll) to about 7 inches high, so as to accommodate the entire RGB LED strip with some space to spare. Also, make the cardboard tube to look as neat as possible, so I covered it with white paper. It's much better to have white instead of brown!
Step 10: Bring Everything Together!
Now that everything's ready, we can start piecing everything together. First of all, fit the ATtiny controller circuit into the tube as shown in picture 1.
Now, peel off the paper on the back of the LED strip to expose the sticky side. Neatly wrap the strip around the tube, such that it goes from end to end in a spiraling manner (see picture 3). It's okay if the white paper is exposed.
Now connect the power pins of the ATtiny controller circuit to the 12V output of the rectifier. Cover up every wire joint with insulation tape.
As finishing touch, I decided to roll a piece of white paper over the LEDs like in the picture below. The paper diffuses he light and reduces the "glare" (the light from the LEDs were too bright). After checking connections, connect the transformer to a mains outlet, and, if all goes well, the LEDs should immediately shine and shift slowly through a series of pink, yellow and orange hues.
Here's a picture of how it looks!