Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling simple relay switch via USB

I'm looking to control a mains powered light from a simple relay switch connected via USB to the computer.

The relay switch isn't even a USB device, it's just a simple switch that requires the USB voltage to turn it on. When the voltage drops below a threshold, the switch will turn the light off.

My problem is that I can't control the power output of a USB port. I'm happy to do it using any language on Windows or Linux (but preferably Java because I'm used to it).

like image 811
Matt Avatar asked Jul 14 '10 12:07

Matt


2 Answers

Unfortunately, in most cases you cannot control the power supply to the USB port. The power supply is usually hardwired through, and not switchable in software. You can send a reset to a USB device, but that won't work in your case.

There are a number of projects on instructables that do similar to what you describe, but unfortunately they seem to either be quite complicated or require expensive parts.

EDIT: There is actually a product currently in the news which would do want you want, but it doesn't appear to be shipping yet: http://www.pwrusb.com/

EDIT (again): Apparently you can do this with some usb hubs. This post sugggests the Linksys USB2HUB4 is one that works.

EDIT (and again): Apparently there are a number of similar questions, but there don't seem to be any more useful answers:

  • https://stackoverflow.com/questions/405269/custom-usb-device-that-disables-power-to-usb-devices-plugged-into-it
  • Power off an USB device in software on Windows
  • Is there software or code to alter USB power output
  • Can I write a program that swiches USB on/off
like image 199
Colin Pickard Avatar answered Oct 14 '22 11:10

Colin Pickard


Most of the USB to Serial or USB to RS232 $10 converters support hardware handshaking. Use one of those as a single channel digital io.

Connect your transistor that will drive the relay to DTR on the converter board and command DTR ON/OFF with the converters driver.

A 2N7002 is a good transistor to use (FET actually) since it will work from 3V and doesnt need any resistors anywhere.

like image 31
Tony Richardson Avatar answered Oct 14 '22 10:10

Tony Richardson