Simple(?) USB switch of some sort?

Started by
5 comments, last by nobodynews 17 years, 6 months ago
Hello, How can I connect, say, an LED or small flashlight bulb to a USB port or other common computer port so that I turn the light on and off by clicking a button in a program? This is an important project to me, and I'm willing to spend some time. Google wasn't terribly helpful, so if you know of any good resources that might be of some help to me, please let me know. Thanks for your time, Adam Background: I don't know a whole lot about hardware, but I'm fairly experienced in C++, VB, etc. I've taken lots of electronics classes at my high school, but I haven't learned how to interface computers and other circuits.
Advertisement
I know absolutely nothing about this, but this wikipedia article seems like a good starting point: clicky! Good luck!
How are your low-level skills? Power is supplied to the USB socket when you plug it in, so you could just have a light for that power - but you want to be able to toggle it from the computer. I think you'd then need to have a microcontroller (maybe a little PIC such as you'd get in some starter kits?) connected to the light to control whether it was on or off. Exact implementation details would then be quite specific, however. That said, if you have even a little understanding then it should be relatively simple.
[TheUnbeliever]
You may want to look at parallel or serial port interfacing first, as they're probably simpler than USB (Personally I've never done any USB interfacing, but I've done stuff with the parallel and serial ports).

With the parallel port you can simply switch certain pins on or off and also set them to input or output mode, the parapin which is for linux makes this very easy. I think there's a similar library for windows but I can't recall its name. The parallel port can't source much current, it should be enough to drive a few LEDs (remember you need a resistor in series), however if you want to drive a flashlight bulb you'll want an external power supply, you can use a transistor to switch it on and off.

Serial interfacing is a little trickier, AFAIK you can't just switch individual pins on and off, you'll need a chip that can understand the serial protocol, you'll also need an rs-232 transceiver to do some voltage level conversion (RS-232, i.e. the serial port uses some slightly odd voltage levels that need to be converted to 5v or 3.3v logic levels). Microchip PICs can easily interface with a serial port. Some PICs can also interface with USB.

Also a warning, I recently blew up my motherboard and I'm pretty sure it was due to my carelessness with the serial port, I had a load of wires comming out of a plug that I'd soldered and one of the bare ends got shorted to the case ground (or something like that). So when you do do this be careful or use a computer you don't mind blowing up (there's also the option of USB->Serial or USB->Parallel convertors or getting a seperate I/O card so if you screw up it'll probably just blow that up rather than the entire motherboard).
One way to do it is to use a digital I/O module like this one. This might be an overkill if you just want to have one LED, and it costs money. But it also will let you have more than one light, and since it also can take input, you could for example let the user switch a hardware button that in turn switches a button in your program.

These modules are delivered with a C++ API and is fairly easy to program. But you will need some hardware knowledge of how to connect the light and buttons to the module.

This module is just an example, there are different vendors and products. Search for "data aquisition usb" for example.
Well, if you want to do it yourself from buying the parts, drawing the traces and soldering the circuits, you'll need to learn a bit electronics and digital integrated circuits (ICs).

A good resource i learned from is here: http://www.play-hookey.com/digital/
Check "the logical story" and try to understand each example. you can even get a demo version of "electronic workbench" to actually see the thing working.

keep in mind that usb is serial (even by his name), and to control multiple elements, you'll need some kind of parallel handling, like (check the site again) a serial to paralel converter. you can, for example, control 8 leds with the usb, but you'll need to get a bit in-depth of electronics.

with only one led, it should be enough one of the 2 data pins, but heh, i'm sure that at a latter point you will not want to control only one led, but perhaps a simple number screen, or even an array of leds.

best of all,
izua

[Edited by - izua on October 14, 2006 10:45:52 AM]
Funny, I'm doing a similar project. Except instead of turning on an LED we're sampling data from various sensors, buffering it in hardware, and then transmitting it to a PC from USB at variable sampling rates.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

This topic is closed to new replies.

Advertisement