Introduction: Controllable Back/Mood Light With Arduino
Hello everyone, my name is Nick. I have lurked on Instructables for several years now and I am finally making my own Instructable! I hope everyone who reads finds some inspiration or knowledge that they can apply to their own projects.
I decided to make this Controllable Back Light or Mood Light to add some personal touches to my office space at home. My computer has a set of LED lights that can either be solid colors, or transition in a repeating pattern from one color to another. I thought to myself that it would be nice to have something for my keyboard that could do the same. So the controllable Back Light Idea was born!
I am applying this concept to a Back Light stand that my keyboard rests on, but it could easily be modified to be used for many other purposes like lamps, frames, cabinet lighting, bracelets/necklaces and more.
Let's get started!
Step 1: Tools and Materials
Let's start by gathering all of the necessary materials.
The components needed are:
6 AA batteries
Shrink Wrap Tubing
The Tools needed are:
Soldering Iron and Solder
Hot Glue gun
Bread Board - Optional
Step 2: Design - Determining Components
The hardest part for me was determining the what components I needed.
I started by measuring the perimeter of my keyboard and determined that in order to get good lighting around the whole edge of the keyboard, I would need 3 LEDs per long side and 1 LED per short side for a total of 8 LEDs. I also wanted to have multiple color options for LEDs, I decided on 5 colors for 40 LEDs total. I then ordered the multipack of LEDs from Amazon.
Each LED in my pack draws about 20 mA of current and the voltages vary by color from 2.2 to 3.4 V. I planned on using an Arduino board as the controller because I have used them in other projects. Arduino cannot handle currents much larger than 20 mA without being damaged and can only output 5 V. This means that either all of my LEDs would have to be on its own pin, or I would have to find a different power supply and a driver to control an array of LEDs.
I started by sourcing the battery. The Arduino Nano has GND and Vin pins that can easily be soldered to and can accept 9V. 9V is a good amount of voltage because several LEDs can be connected in series. 9V batteries are not very good for performance to cost so I opted for a 6 AA batteries connected in series to make my 9V.
I then dug through my components to find a driver for the LEDs so I could control the larger voltage and higher currents without damaging my Arduino. I decided to use a MOSFET to control the LED states. The one that I had on hand was the NDD02N40. It has a gate threshold voltage (the amount of voltage to be considered HIGH) of between 0.8 and 2.0 V, easily achieved by the DIO pins of the Arduino. It can also handle a continuous drain current of up to 1.7 A and voltage up to 400 V. It is probably a bit overkill but it should work no problem.
Step 3: Design - Electrical Layout
With the components selected, I started laying out the circuit. To fully optimize the 9V, I used LED Series Wizard to determine how to arrange my LEDs to have the fewest wires. An example can be seen for the Blue LEDs. I took the 9v for the battery, 20mA for the current, and used 8 as the total number of LEDs I needed for that color. I then set up a circuit on the breadboard to test the layout.
Once I verified everything was working, I put together the total schematic. The final schematic has 5 arrays of 8 LEDs. The LEDs connect on the positive side to 9V, go down through the resister, then connect to the Drain of the MOSFET. The Source of the MOSFET is connected to ground, and the Gate is connected to either PWM 11, 10, 9, 6, or 5 of the Arduino. There is 1 MOSFET per color, so all of the colors can be controlled individually.
There is a tactile switch that will be used to change the color mode. It has a 10k resister going to ground to prevent any random signal readings. There is also a power switch between the batteries and the board so the lights can be turned on/off without the need to remove a battery.
Step 4: Design - Giving It an Enclosure
For an Enclosure, I wanted something relatively slim so that it could fit under my keyboard without changing the height too much. I also wanted something that was light and easy to move. There also needed to be a battery box that had room for a tactile switch, the power switch, and the control board. It would also be nice to have holes for the LEDs to mount in so that all of the spacing would be equal. I took all of these into account when I was designing the prototype for the enclosure. I broke the enclosure into two parts, the LED holder and the Battery Box.
For the LED holder, I first started by measuring my keyboard, then subtracting an inch from each dimension so that the finished LED holder would be hidden by the keyboard. I then determined that my 3D printer would not be large enough to print the whole part, so I broke it up into sections. There are 3 sections for the long side of the keyboard, and 1 section for the short end. The sections were made into a U shape so that the keyboard would not put weight on the LEDs. I put 5 evenly spaced holes in the center of each segment to hold the LEDs. I made some rectangular and triangular sleeves that the ends could slide into to give them some strength when assembled.
For the Battery Box, I started by laying the battery holder and controller board next to each other. I then measured the 2 next to each other to determine the size of the Battery Box. I added about a quarter of an inch to the measurement to give room for wires. Next I laid out key components like the micro controller and tactile switch on the controller board to estimate height and location of the USB cutout, the tactile button cutout, and where to route the wires from the LED holder.
The final parts I ended with are attached:
Step 5: Design - Code
There were a few functions I wanted my Keyboard back light to perform. My PC fades from one color to another and I wanted the back light to perform a similar function. I also wanted to be able to switch from one color to another without having to go into the code, make a change, then upload the changes to the Arduino, so I needed some sort of function to change the state of the lights and I need a signal to tell when to command the change. This is where the tactile switch comes into play.
The final code was set up to have 4 parts. The Setup, a Switch statement to command the LEDs, a button press function that reads in the button state and increments the mode to the next LED function, and a Fade function that changes the intensity of the LEDSs from dim to bright and back to dim again.
The completed code can be found below:
Step 6: Assembly - Building the Holder
By far the quickest part of the assembly process was assembling the LED holder and the Battery Box. I started by printing all of the .stl files on my 3D printer. Once all the parts were complete I preheated the hot glue gun. While that was warming up, I dry fit the pieces together to make sure they all fit.
I started by assembling the short ends to the shorter pieces of the long side. I put some hot glue on the short end and pressed the pieces together making an L shape. Once the glue set, I put a little glue in the triangular end cap and fitted it over the new corner. I repeated this for the other 3 corners. Then I took one long side center piece, put some glue on the end, and slid it half way into a sleeve. I repeated this for the 3 other ends so I had 2 dumbbell-shaped pieces. I then put glue on one side of the the two U-shaped pieces and slid it into a sleeve. I repeated this until all pieces were glued together to form a rectangle.
At this point, I started to insert LEDs into the LED holder. It was a tight fit, so I had to line an LED up with a hole and use a pliers to pry the gap open a little bit so the LED could slide in. I arranged the LEDs Blue, Green, Yellow, Orange, Pink. I used this same pattern for each set of 5 until all 40 LEDs were in place. I then used a little more hot glue to tack each LED in place so that it wouldn't fall out during soldering or when the whole assembly was moved in the future.
Step 7: Assembly - Soldering
This was by far the hardest task of the whole project and took the most time to complete.
I started by wiring the positive ends of the series for each array. This lead to 4 leads for each color. I wired the leads to a grouping on a separate perf board. I then attached another lead to the grouping. This was the lead that I would attach to 9V during final assembly. I color coded each wire as I went.
Next I wired the negative end of the adjacent LED to the corresponding resistor for the color shown in the schematic. These negative leads I also wired in groups to the perf board by color. Another lead was attached from each color group. This will be attached to the Drain pin of each MOSFET during final assembly.
Last but not least, I used female-to-female jumper wires to connect the "gaps" in the LEDs, bridging the negative end of the LED connect to 9V and the positive end of the LED connected to the Drain.
The Controller Board:
I started by soldering the Arduino Nano to the perf board. I then arranged the MOSFETs so that they were evenly spaced along the digital pin side of the Nano. I connected the GND pin of the Nano to the GND Rail and the VIN pin to the 9V rail. Next I connected the Source pin of each MOSFET to the GND Rail. I connected PWM pins 11, 10, 9, 6, and 5 each to one Gate pin of a MOSFET. I placed the tactile switch on the perf board, connected one side pin D13 and to GND through a 10k resister. The other side was connected to 5V on the Arduino.
Step 8: Assembly - Putting It All Together
Now comes the fun part, putting it all together!
I started by mounting the battery holder in the Battery Box with some hot glue. I then stripped and tin the wires for the battery holder leads. I put the SPDT switch into place and wired 9V to the the middle terminal. I cut another wire and placed it on one of the outside terminals and the 9V rail of the controller board. GND was connected directly to the GND rail of the controller board. I then screwed the the SPDT switch into place and tested if the board could be powered. Next I mounted the controller board.
I lined up the the tactile switch with a hole in the top of the Battery Box and lowered the board on the standoff, careful not to pinch the wires from the batteries.
I then used 3 more screws to screw the board down to the standoffs, securing the board in place.
Next, I ran the leads from the LED holder through the cutout I left in the Battery Box. I started with the ground wires. I started with the green array lead and soldered it to the Drain of the the first MOSFET. I repeated this for each color. The order I soldered was Green, Blue, Pink, Yellow, Orange. After each GND/Drain connection was made, I connected each 9V wire from the LED holder arrays to the 9V rail of the controller board.
I powered on the the system and tested that each LED was connected correctly by cycling through the functions of the controller using the tactile switch. The green LEDs didn't light up initially so I probed the connections with my Multimeter. It turns out the GND/Drain connection for the Green LED wasn't good. I re-soldered the connection and everything worked! All the hard work payed off.
Step 9: Conclusion
I would say that overall, I am happy with the results of the prototype. I tried using it with my keyboard and it didn't interfere with the normal operation. It seems sturdy, time will tell how well it holds up. The push button transitions the states pretty smoothly and I enjoy that I can change the light effect to reflect my mood. Below are some videos of the final assembly in action.
I learned a lot during this project. I determined that it is better to have a wiring plan ahead of time, it saves a lot of time, effort, and space not having so many wires. It is also a good idea to test things as you go. I had several cases where testing the electrical connections would have saved time later down the road when I was trying to figure out what the heck went wrong.
Future plans for the Version 2.0 include adding an LCD screen with more buttons so you can select what LED function you want from a menu. I also plan to add more functions, like fast/slower fade, blinking speed variations, and maybe mixed colors. I would also like to add some PC serial monitoring, maybe have the LEDs change color based on PC temperature, or network speed. Keep checking back as I will likely keep adding more to this project!
I would also like to redesign the LED holder and Battery Box to both be one assembly. This would likely be achieved by laser cutting parts for a long base and top panel that could sandwich the LED holders, and the Battery Box could sit on top of. It would also be nice to laser cut and etch some acrylic to place in front of the LEDs to diffuse the light and give a more uniform glow surrounding the keyboard.
I hope you all enjoyed this Instructable. If you have any questions or comments, I would be more than glad to answer them.
If you learned something in this Instructable or were inspired to use parts of my project in your own project, please vote for this project in the "Lights" competition.
Thank you :)