Controlling simple relay switch via USB

前端 未结 6 2040
死守一世寂寞
死守一世寂寞 2020-12-24 04:40

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 s

相关标签:
6条回答
  • 2020-12-24 04:59

    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
    0 讨论(0)
  • 2020-12-24 05:01

    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.

    0 讨论(0)
  • 2020-12-24 05:04

    Here is a complete solution.

    It uses an Arduino board, with a USB connection, (and Uno for example) to control the relay and combines this with pfod (Protocol for Operation Discovery) www.pfod.com.au which will let you control the board/relay from either the Arduino IDE SerialMonitor, or a terminal window (TeraTerm) or a Java program. The message protocol encloses commands in { }, think simplified html for micros, and provides numerous screens, menus, sliders, text and numeric inputs, etc. A detailed protocol spec is available

    See Garage Door Remote for a detailed example, with full Arduino code and an example of controlling the relay from TeraTerm as well as the Arduino IDE SerialMonitor.

    There is also an Android app, pfodApp, which will do general purpose control via bluetooth, or wifi/internet with 128 bit security. The pfodApp does all the Android stuff, you only need to code some simple strings in your Arduino code to get any menu system you want. See www.pfod.com.au for numerous examples.

    0 讨论(0)
  • 2020-12-24 05:07

    You could do it by combining these two products from Pololu, for about $25:

    1. Micro Maestro (assembled)
    2. Basic SPDT Relay Carrier with 5VDC Relay (Assembled)

    The Maestro is mainly a servo controller but you can set any of its channels to be simple digital outputs instead. The output can be controlled from the Maestro Control Center software or you can write your own software. A digital output from a Maestro is suitable to turn on the relay on the relay carrier. The relay could be powered from USB through the Maestro; I think it draws about 100 mA of current so that probably will not be a problem for most USB ports, though it would not be USB-compliant because the total current drawn by the Maestro and the relay would be over 100 mA. You could supply your own power source for the relay if you are worried about that.

    0 讨论(0)
  • 2020-12-24 05:10

    I would suggest placing a separate Raspberry Pi unit with a wake-on-lan feature activated so you can ping it off and on.

    0 讨论(0)
  • 2020-12-24 05:23

    You need a USB-GPIO microcontroller:

    Adafruit FT232H (about $15)

    Arduino Nano ATmega328 (about $7) 2

    See this answer

    0 讨论(0)
提交回复
热议问题