Introduction: USB Controlled Mini Lava Lamps
This instructable describes the building of a USB powered and controlled set of lava lamps from a USB keyboard and two Think Geek USB lava lamps using a simple transistor relay switch circuit driven by the keyboard LEDs. It illustrates a simple way to control up to three high-latency switches (at up to 120volts, 0.5 amps) over a USB connection, for a minimal amount of money (0$ to 40$ depending on your junk collection), and without having to program a USB serial control driver or a microcontroller. Potentially you could also use the keyboard keys to add over 100 inputs that would type characters that could be used to control a program (as described by randofo and by David Merrill, but this approach was not used for this project.
This project was conceived as a present for my friend Chris Lasher to commemorate his moving and beginning a graduate program in bioinformatics. Chris will be doing a lot of programming, and is an adherent of Pragmatic / Agile Programing, one of the principals of which is unit testing. While the unit tests of a program are running, it is nice to know if they are succeeding or failing, and which is predominant. Famously, some pragmatic programmers made a feedback system by controlling full-sized lava lamps from a unit testing framework by plugging together some off-the-shelf home control devices (it cost them over $60). The lamps allowed them to see whether tests were passing or failing, and the gradual heating up on one lamp allowed them to see which events were predominant. This is a cool idea, but I wanted to make Chris something that:
1) would control two small USB-powered lava lamps,
2) would be powered off Chris's fancy new laptop, and interface via USB (no legacy ports on newer computers, particularly laptops),
3) would be a bit more homemade and hacker-friendly,
4) would be allot cheaper.
Driving relays from a USB to serial port converter would seem to be a simple solution. There are many circuits available on-line for serial port control projects. One excellent project that I adapted was at http://www.windmeadow.com/node/4. Unfortunately, almost all USB to serial devices do not allow for low level bit banging (the manually toggling of control lines) that is required to use these circuits. Another approach would be to buy a USB interface circuit, or build one from a microcontroller. Either way, the project would require a good deal of microcontroller code and drivers (even using the pre-existing human interface drivers or a pre-made controller).
I chose to solve this problem with a salvaged USB keyboard, since they are relatively cheap, and contain everything that is needed for three simple on/off outputs, in the form of the number, caps, and scroll lock LEDs. Under Linux there are a number of mechanisms to toggle your LEDs from a program or command line (one is even referenced in Cryptonomicon). Setled is the simplest, and is pre-installed on almost all machines, ledd is built on a client-server model, and there is even a module in the Ruby programing language. Windows and Mac OSs, and other programming languages, should have comparable mechanisms - post them in the comments if you know how to toggle keyboard LEDs in other OSs or programming languages!
I gave Chris his present, and now he can not only see if his unit tests are passing, all the programmers in his new department can know what a cool DIY maker he is.
Step 1: Parts List
2 USB lava lamps (from Thinkgeek or froogle ~$10 each)
1 USB keyboard
(an apple keyboard would also allow you to salvage two USB jacks, making the hackery listed in the "poor man's USB jack" step unnecessary)
$0 for a scraped keyboard with a dead key or two, to $4 on-line (http://froogle.google.com/froogle?q=usb%20keyboard) to $30 at best buy)
2 reed switch relays (Radio Shack #275-233 $3.00, Mouser #677-OMR-112H $1.54)
all other electrical components should only cost a few dollars.
2 transistors (like a 2N2222) (Radio Shack #276-1617, Mouser #511-2N2222A)
2 resistors (Radio Shack #271-1124, Mouser #291-4.7k, yellow-violet-red-gold bands)
4 diodes, something like 1N404 (Radio Shack #276-1103, Mouser #512-1N414B)
1 power switch (SPST)
a little bit of wire
1 perfboard (Radio Shack #276-1395)
1 Altoids tin
some cardboard, a sheet of transparency/overhead film
Tools:
soldering iron and / or wire wrap tool and wire
dremel tool or hand-tool and patience
drill and bits
a digital multimeter
red and green sharpie marker
Knowledge and skills:
Basic soldering and electronics knowledge. I highly recommend Forest Mimm's book if you are an electronics beginner and would like to know how circuits work.
Time:
This project took two evenings and an afternoon, including troubleshooting.
Step 2: Keyboard Evisceration
Take your keyboard apart as nondestructively as possible. The keyboard I had lying around was a Dynex multimedia USB keyboard, model number DX-MKB101. As you disassemble, be careful not to break the thin wires that are often used. You should see something like the second picture after opening the keyboard. You want to salvage the body of the circuit and the board with the LEDs (often on the same circuit board) and lose the bulky keyboard. Hopefully you can detach the thin plastic film that acts as the key switches for the keyboard, or in some other way cut off the keyboard switches without damaging the main circuit. I had to cut through some plastic to liberate the board, but after finishing you should be able to plug the keyboard in, have it recognized, and toggle the bare LEDs with another, functional keyboard's lock keys pluged into the same computer. You can have multiple keyboards, USB and not, plugged in simultaneously with most modern operating systems and they will trigger each other's caps lock and other lock keys. At this point I should say that it is possible to damage or destroy your computer by plugging bare circuits into it. Use caution and proceed carefully. If you are worried test with a cheap USB hub. On the other hand, I tried all sorts of things while troubleshooting this circuit, including rewiring live circuits, and my laptop remains unfried.
Step 3: Poor Man's Usb Plug
I did not want to destroy the USB plugs on the lava lamps so that they could be used separately, and so that the USB lava lamp controller was modular (other devices could be used switched on and off instead of the lamps). If you disassembled an apple keyboard in the last step you would have have two female USB-A jacks that you can use, and so can skip this step. You could also purchase the female USB-A jacks from mouser or salvage ones from a spare USB hub. I chose however to go with a cheap and simple option - a simple USB jack made from some striped wire wrap (any thin wire would suffice), a bit of perfboard, and some paper and transparency film for insulation. Simply cut a bit of perfboard to go INSIDE the USB plugs, add wire through the holes so that inserting the plug will not pull them out and will allow them to contact the +5V and ground connectors in the plug (see the pinouts on the "Make circuit" step for which connection is which). Then cut some transparency film to cover one side of the board so the perfboard wire will not short out against the metal body of the plug. Jam this insulated board into the USB plug, and confirm with your multimeter that the wires make a good contact and are not shorting. These are how the USB lava lamps are connected to the circuit. For this project, make two of these poor man's plugs head-to-head on the same bit of perfboard (see the image). During the assembly step, you will see how the case holds both of the USB plugs on this connector.
Step 4: Cut Enclosure and Perfboard
Figure out the layout of your project in it's enclosure. I used the ever-popular Altoids tin. Drill a hole in the back of the Altoids tin for the large on/off SPST switch, one in the front for the keyboard USB cable, and two holes in the sides for the USB lava lamp plugs. Cut keyhole slits with a dremel cut-off wheel or handsaw down to the front and side holes so the USB cables can fit in (see picture). Line holes with duct tape to prevent cutting of cables. Decide on the shape of your perfboard for your circuit and cut out that shape with a dremel tool. This is going to be a pretty tight fit . . .
Step 5: Make Circuit
The heart of this project is simply using software to toggle the keyboard LEDs, and hijacking the LEDs to switch larger currents. I should mention here that some LEDs are switched on by applying a positive voltage to the anode, while other circuits (like the one in this keyboard) float the LED anode high (so the LED is off) and tie the cathode of the LED to ground when it is activated (pull-down switching). You could modify this circuit to work with either, but I will diagram the negative tie-down method. The LED being turned off (set high) turns on a transistor switch, which closes a relay, and finally the lava lamp is activated. This means that the software toggle for the lamp will be reversed from the LED. I adapted the circuit from windmeadow, but it is based on a simple transistor switch as described in most electronics texts (p. 50 in Mimm's book, or on wikipedia). I have included a ktechlab file so you can see how the transistor switch works, and a full schematic (in svg and png formats). Be sure to use the original schematic or the svn file for printing out, as the smaller images are not clear.
You will need to remove the LEDs from the keyboard circuit board and determine their polarity and which side is switched with a multimeter. Run one wire from each LED that will be involved in a switching circuit (these are labeled SCROLLLOCK and CAPSLOCK on the schematic). Desolder the +5v and ground from the keyboard circuit to provide power to the perfboard, and then run wires to return power to the board (this is the +5V and grounds on the schematic). Then follow the schematic to make the circuit, using the pinouts of the components to identify connections. Assemble this circuit on a breadboard first, and test the circuit. This was the step where I determined that the LEDs were pull-up instead of pull-down switched, and generally reached the point of maximum chaos on my workbench. When the circuit works (testable by hitting the Caps Lock Key or Scroll Lock Key and seeing if the lava lamps toggle), figure out how to pack the components onto the perfboard. Wirewrap can be used, but the simplest assembly method is to simply shove components through holes, wrap the leads together, and solder them together. Test that the assembled circuit works on the perfboard.
Step 6: Color USB Lava Lamps
Make the clear USB lava lamps colored by coloring a patch of the overhead film with the red or green markers, then cutting out a circle to insert in the base of the lamp between the light and the "lava" chamber. Reassemble lava lights.
Step 7: Final Assembly
Altoids tins make great enclosures. They are good at shielding, but they unfortunately are conductors and will short unprotected circuits. To prevent this, cut cardboard and transparency film to the size of the tin, and to fit between the keyboard circuit board and your perfboard. Insert switch in the back hole in your tin. Insert USB plugs mated to the poor man's USB connector into the keyhole cuts in the side so that the tin holds the plugs into the connector. Cram in perfboard and salvaged keyboard circuit, insulate with the cardboard and transparency film. Try to close the tin (ours barely fit).
Step 8: Code
The lava lamps will be controlled by system calls to the "setled" program that will turn on and off the capslock and scroll lock LEDs. Test it out by running the following from a command line (possible as root, depending on your configuration) to make your lamps blink:
setleds -L -caps +scroll < /dev/tty0 ;sleep 3s ;setleds -L +caps -scroll < /dev/tty0; sleep 3; setleds -L </dev/tty0
breaking this down:
#To turn on the red lamp:
setleds -L -caps +scroll < /dev/tty0
#to turn on the green lamp:
setleds -L +caps -scroll < /dev/tty0
#to return to the state where the LEDs display the keyboard settings
setleds -L </dev/tty0
You can include these system calls in your own program, or use the a phython unit test module that Chris wrote based on the PyUnit unit testing framework built into python. Just unpack the files from the tar archive (tar -xzvf lava_unittest.tar.gz from a console) and try the following commands from a console:
python lava_unittest.py test_lava_unittest-pass
python lava_unittest.py test_lava_unittest-fail
or
python test_lava_unittest-pass.py
python test_lava_unittest-fail.py
To run from a terminal emulators, uncomment the warning-flagged lines and try running it
as root from a terminal emulator.
With this code, all one needs to do is swap instances of "unittest" with "lava_unittest" in Python scripts written for unit testing. No re-coding is necessary.
Attachments
Step 9: Pretty Packaging
To finish this project, make and print out your own label or use the included image (open the full-size secong image or the xcf file with the gimp). Simply paste on the cover of your amazing USB controlled lava lamps.
Attachments

Participated in the
The Instructables Book Contest
23 Comments
11 years ago on Introduction
Great idea using the caps lock as the switch, recommend that you never plug the lava lamps into the usbs as they easily burn out your USB plugs. Buy a 5v wallwort and power the lamps with that
Reply 11 years ago on Introduction
These lamps were made to be powered off a USB source, and their draw is well below what my laptop can deliver. The recipient of this gift hasn't had any problems with it. Thanks for the concern though.
12 years ago on Introduction
I made one recently with code to interface it to Hudson:
http://wiki.hudson-ci.org/display/HUDSON/Lava+Lamp+Notifier
Reply 12 years ago on Introduction
Neat! It's cool seeing built-in support for such a rare piece of hardware!
Would you mind including a link on that page, for people who might find your page, but are interested in making one for another unit testing system?
13 years ago on Introduction
i wana make the USB connected music player with schematic & circuit diagram ,with a deiail information can any of u provide me this please i can't find the detailed circuit with detail information
14 years ago on Introduction
what program is used to create and read the .circuit files?
Reply 14 years ago on Introduction
It is the KDE / Linux program Ktechlab, which is under heavy development by a new group of people, but still rather beta software:
http://ktechlab.org/
http://sourceforge.net/projects/ktechlab/
There is really not much more information in the .circuit file than in the .svg diagram, but ktechlab is fun to work with when it doesn't crash.
Hope that helps!
15 years ago on Introduction
This is awesome. I found this a while back and used this technique to make my air conditioning controllable from my phone. Thanks!
16 years ago on Step 1
For the reed switch relay, #275-233 is the 12V relay. #275-232 is the 5V relay you want. These are rated up to 0.5A at 125VAC, but I'm probably not going to hook up a wall-powered lava lamp to them any time soon...
Reply 15 years ago on Introduction
hiya - i'm trying the circuit with a 5v relay and having a few problems in the circuit around the resistor and transistor - do these need to be different ratings also compared to the 12v setup? Thanks
Reply 15 years ago on Introduction
What sort of problems are you having? Does the circuit work without the relay? You can test it with a multimeter, or make a little LED+resistor logic probe. The 5v relay should not change the values of the resistor. If you give me more information, I'd be happy to try to help you find out what's going wrong.
15 years ago on Introduction
use a comparator for a cool light show!
16 years ago on Step 3
I didn't have much luck with the poor-man's USB plug - too prone to becoming disconnected. What worked like a charm was a PCI-card USB plate, often included in motherboard kits. We had a firm USB connection, and the other end was a female plug for a motherboard, making it trivial to insert our own wires. Also, I'm not sure an apple keyboard is a good bet - my current keyboard just has one LED, for the caps lock button, and this project requires at least two.
Reply 16 years ago on Step 3
I'm sorry the poor man's plug didn't work for you - perhaps my perfboard was just the right thickness so that when I threaded the wire-wrap wire through the holes and added label tape on the other side it was just the right size to stay jammed in the USB plug. The PCI-card USB plate is a great idea for salvaging female USB plugs. I'm not sure about the apple keyboards, I think they have changed quite a bit over the past few versions. Thanks for the suggestions, and I hope you are enjoying the USB controller.
16 years ago on Introduction
how would i connect my Christmas lights to my pc.
Reply 16 years ago on Introduction
Xmas lights (even LED ones) would probably draw too much power to be operated with this circuit, but you could probably use this circuit to turn a relay on and off that would regulate wall power to the lights. There are allot of Xmas light projects by others, they would probably be a better place to look for plans.
16 years ago
ingeneous ive always wanted an easy way to control relays through my computer, and using the led outputs of a keyboard seems the perfect way to do it great job
16 years ago
If you do want to use a microcontroller to have a USB controler, take a look at the USB Bit Whacker.
16 years ago
Thank you for figuring out how to turn the keyboard lights on and off with code. I've been half-heartedly attempting to do this for ages. Well done.
Reply 16 years ago
Thanks! I'm glad you liked the instructable. But I didn't actually figure out how to toggle the keyboard LEDs - I'm just standing on the shoulders of the giants that built linux. Setled has been around for ages, and Chris, the recipient of my gift, wrote the nifty code that used this gift as an output for the python unit testing framework. If you are interested in using keyboard LEDs as output, see the simple command line in step 8, or if your needs are more complex look at how Chris used it in a python script or at the daemon ledd.