I'm giving some workshops in electronics in a few weeks, centered around an inexpensive, but useful real-world project. When trying to come up with a thing to make, I wanted it to involve a microcontroller, NeoPixel LEDs (because, they're awesome), be remotely controllable, and allow for different build options. It also had to be fully simulatable in Autodesk Circuits. This is the project that evolved.
It packs some really cool features into a small device, is customizable, and is fairly simple to build.
As I mentioned earlier, I wanted to use the free Autodesk Circuits for this project. I decided to fully design, and test it there before ever touching any real electronics. This allowed me to make sure that everything (including the ATtiny85 firmware) would work. Here's that virtual circuit. You can press "Start Simulation" below to try it out.
This project is designed to allow flexibility in how it is built. So, depending on what you want to do with it, you may not need all of the parts. There are three parts (and wire) that are absolutely necessary. It is possible to build something functional with just these.
Neopixel Ring 12 - the ring has twelve NeoPixels that can be individually controlled to be just about any color.
ATtiny85 - this is the microcontroller (tiny computer) that makes the NeoPixels dance, and interfaces with several of the optional components (infrared receiver, pushbutton, etc.).
Printed circuit board - the printed circuit board (PCB) provides all of the electrical connections between the parts used, and is the rigid backbone of the device. The gerber file that is sent to a PCB manufacturer can be obtained here. Click the "Download Gerber" button to get the file. There are many board manufacturers out there. Here's one.
22 gauge solid-core wire - the wire is used to connect the NeoPixel ring to the PCB.
There are a number of optional parts that you might want to consider including. Here's why you might want them.
Infrared receiver - the infrared receiver is a single component that will allow the device to be controlled by a standard handheld IR remote controller (think TV remote). Remote controllers from different manufactures emit different signals, so the firmware may need to be modified to recognize your remote, if it is not one of the ones that I used.
1μF electrolytic capacitor - the capacitor acts as a sort of temporary battery that can provide additional power when the needed electrical current in the device changes abruptly (NeoPixels go from off to full-on, for example). It also can even out the voltage to the device when using a cheap USB power supply. If you are using a decent USB power source, then this can be left out.
Pushbutton - the pushbutton allows you to control the device by (guess what?) pushing the button.
Male 3-pin header(s) and shunt jumper(s) - these can be put in place instead of the pushbutton to allow the device to be configured, based on how the shunt jumpers are positioned. The male 3-pin header gets permanently connected (soldered) to the board, and the shunt jumper is press-fit on the header and can be easily removed and repositioned. If one header is used, then the jumper can select between two different modes. If both headers are used, then four modes are possible.
8-pin DIP socket - the socket allows the microcontroller (ATtiny85) to be removed and replaced so that it can be reprogrammed later if you want to change how the device works. If you know that you will never need to reprogram the microcontroller, then this is not needed.
4-pin right-angle header - the right-angle header is used if you desire the USB connector to stick straight out of the back of the device, instead of from the side.
I'm not going to go into too much detail about programming the microcontroller, because instructions are easily found elsewhere (I include a link below). I used an Arduino UNO board to act as a programming device for the controller using the method described in this Instructable. In it, it shows the following mapping from Arduino pins to ATtiny pins for programming:
The source code for the night light can be found here (https://github.com/cacklestein/led-night-light).
Parts should be added to the board in a particular order to make things easy. If you are fine with the position of the USB connector on the board, you can skip the rest of this step and move on to the next part of the assembly. However, if you desire the connector to stick out the back of the board, now is the time to add the right-angle header.
Start by carefully snapping-off the USB connector from the rest of the printed circuit board. Hold the larger part of the board with one hand and use pliers with one edge directly next to the perforation line of tiny holes to carefully remove the tab. Set the tab aside. you will need this in a later step.
Position the right-angle header on the back side of the board as shown in the picture. The back of the board is the side with "123D CIRCUITS" silkscreened on it (or perhaps I should say "123D CIRC", because you just broke off the "UITS").
Solder the header in place, applying solder to the top side of the board.
Using good wire cutters, snip the leads of the header that protrude from the top side of the board as close to the board as possible. This is important because those leads are sicking out somewhere in the center of where the ATtiny85 will eventually go.
Now's the time to solder either the 8-pin DIP socket -OR- the ATtiny85 in place. I highly recommend using the socket, because it allows the ATtiny85 to be easily removed and reattached in case you want to make changes to the program later.
Fit the socket (or the ATtiny85 with pin 1 nearest the board edge) through the matching 8 holes on the top side of the board. The top side is the one without "123D Circuits" printed on it. Flip the board over and place it flat on the table or other workspace to hold the socket in place. Solder the pins to the board. If you added the 4-pin right-angle header in the previous step, then those pins will be somewhat in the way. Angle the iron to solder under them.
Now's the time to add the button or jumper header(s), the IR receiver, and the capacitor.
If you want to have the pushbutton, fit the 4 pins through the holes below the microcontroller socket on the top side of the board. You will notice that there are 6 holes. Don't worry about this. The two holes in the middle won't be used. Flip the board over and solder the pushbutton in place.
If you want to use the shunt jumpers instead, insert the two 3-pin headers (shorter side of pins down) into these holes on the top side. Again, flip the board over, and solder the pins in place.
Next, fit the infrared receiver through the 3 holes on the top side of the board. Match the orientation of it to the outline on the silkscreen. insert it as far as it will go, and bend it back so that the small bubble side faces up away from the board. Flip the board over and solder this in place. Use wire cutters to remove the excess length of the pins from the bottom side after soldering.
Finally, add the capacitor. Its pins fit through the remaining two holes above the infrared receiver. The white stripe on the side of the capacitor ('-' negative side) faces away from the ATtiny85 socket. Again, flip the board over, solder the leads in place, and clip off the excess with wire cutters.
The NeoPixel ring is attached using 4 pieces of 22 gauge solid-core wire, with the insulation removed. Start by cutting a section of wire at least 4 inches in length. Use wire strippers to remove ALL of the insulation.
Cut this wire into 4 equal lengths. Bend each wire into an "L" shape about 1/4 inch from one end.
With the bottom side of the board facing up, insert these wires into the holes at the 4 corners of the board. The bent section will keep them from sliding all of the way through. Solder them in place, and clip off the bent excess from the bottom side with wire cutters.
Flip the board over, and carefully feed the wires through the 4 holes of the NeoPixel ring with the NeoPixels facing away from the circuit board. Be careful to match the holes of the NeoPixel ring with those on the circuit board. The names of the holes are printed on each. Match PWR, GND, IN and OUT.
Push the ring down as close to the circuit board as possible. Things might be a little tight, especially around the capacitor and the IR sensor. If the ring won't go all of the way down, don't sweat it.
Holding the ring as close as it will go to the circuit board, bend the wires out to hold things in place.
Solder the ring to the wires and clip off the excess wire with wire cutters.
If you chose to have the USB connector stick straight out of the back, now is the time to attach it to the 4-pin right-angle header that you added earlier.
Fit the holes of the tab that you removed earlier onto the right-angle header so that the 4 copper USB contacts are facing the "CIRC" side of the board, and the "UITS" side of the tab is facing the "123D" side.
Solder this in place.
If you soldered the 8-pin DIP socket in place, now is the time to put the ATtiny85 in it.
Align the ATtiny85 such that the corner with the dot is closest to the white dot on the circuit board. Carefully press the ATtiny85 in place, making sure that all pins go where they should.
Typically, the printed circuit boards that you get will be a little thinner than what is expected of a USB connector. A simple solution to this is to cut a small square of Gorilla Tape and add it to the back of the USB connector (the side without the USB copper contacts!). Gorilla Tape is about twice as thick as normal duct tape, and worked perfectly for me.
Plug your new night light into a powered USB wall adapter, or other available USB outlet (on your computer, etc.). If all went well, it should light up! If you added the optional IR receiver, and have a remote control that works with the firmware (like the Apple TV remote in the pictures), you can change the display mode.
Alternately, if you installed the button, you can press it to change modes.
If instead, you installed the shunt jumper headers, then the shunt jumpers can be positioned to change the startup display mode.
If you chose to install the shunt jumper headers, then you can set the startup mode, based on where the shunt jumpers are positioned:
Left position A + Right position A: Rotating rainbow mode
Left position B + Right position A: Color changing mode
Left position A + Right position B: Random sparkley mode
Left position B + Right position B Unchanging solid color mode
I found an inexpensive remote control on EBay that's designed to work with color LED lighting. It seemed a natual fit. I recorded the codes generated by each button and set the firmware to act accordingly. The picture above indicates what the different buttons do.
If you don't have this remote, you can find the codes associated with most other remotes by using the exact same Arduino source code, but on an actual Arduino, instead of the ATtiny85. The program outputs a code associated with any button push of most remotes on the serial console. In order to do this, connect the IR receiver module in the digital pin header slots 2,3, & 4, with the lens facing the rest of the board.
In the picture above, the code 0xFD00FF corresponds to the DFRobot IR remote power button. Here's the code running in Autodesk Circuits. In order to try it out, click "Code Editor", followed by "Serial Monitor", followed by "Start Simulation". At that point, you can start pressing buttons on the virtual remote to see the serial console text output :
Record these for each button of your remote. You can then modify the source code to add the button codes for your remote.