通过USB控制简单的继电器开关
我正在寻找通过 USB 连接到计算机的简单继电器开关来控制电源供电的灯。
继电器开关甚至不是 USB 设备,它只是一个简单的开关,需要 USB 电压才能将其打开。当电压低于阈值时,开关将关闭灯。
我的问题是我无法控制 USB 端口的功率输出。我很乐意在 Windows 或 Linux 上使用任何语言(但最好是 Java,因为我已经习惯了)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是一个完整的解决方案。
它使用带有 USB 连接的 Arduino 板(例如 Uno)来控制继电器,并将其与 pfod(操作发现协议)www.pfod.com.au 它可以让您从 Arduino IDE SerialMonitor、终端窗口 (TeraTerm) 或 Java 程序控制板/继电器。消息协议将命令括在 { } 中,认为是微型计算机的简化 html,并提供大量屏幕、菜单、滑块、文本和数字输入等。详细的协议规范可参见
车库门遥控器 了解详细示例,其中包含完整的 Arduino 代码以及控制继电器的示例TeraTerm 以及 Arduino IDE SerialMonitor。
还有一个 Android 应用 pfodApp,它将通过蓝牙或具有 128 位安全性的 wifi/互联网进行通用控制。 pfodApp 可以完成所有 Android 功能,您只需在 Arduino 代码中编写一些简单的字符串即可获得您想要的任何菜单系统。请参阅 www.pfod.com.au 了解大量示例。
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.
您需要一个 USB-GPIO 微控制器:
Adafruit FT232H(约 15 美元)
Arduino Nano ATmega328(约 7 美元)
查看此答案
You need a USB-GPIO microcontroller:
Adafruit FT232H (about $15)
Arduino Nano ATmega328 (about $7)
See this answer
我建议放置一个单独的 Raspberry Pi 单元,并激活 LAN 唤醒功能,以便您可以关闭和打开它。
I would suggest placing a separate Raspberry Pi unit with a wake-on-lan feature activated so you can ping it off and on.
您可以通过组合 Pololu 的这两种产品来实现这一点,价格约为 25 美元:
Maestro 主要是一个伺服控制器,但您可以设置它的任何通道都可以是简单的数字输出。输出可以通过 Maestro Control Center 软件进行控制,也可以编写自己的软件。 Maestro 的数字输出适合打开继电器载体上的继电器。继电器可以通过 Maestro 从 USB 供电;我认为它消耗大约 100 mA 的电流,因此对于大多数 USB 端口来说可能不会成为问题,尽管它不符合 USB 标准,因为 Maestro 和继电器消耗的总电流将超过 100 mA。如果您担心这一点,您可以为继电器提供自己的电源。
You could do it by combining these two products from Pololu, for about $25:
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.
不幸的是,在大多数情况下您无法控制 USB 端口的供电。电源通常是硬连线的,并且不能通过软件进行切换。您可以将重置发送到 USB 设备,但这不起作用在你的情况下。
有许多关于教科书的项目与您所描述的类似,但不幸的是,它们似乎要么非常复杂,要么需要昂贵的零件。
编辑:目前新闻中实际上有一种产品确实需要您想要的,但它似乎尚未发货:http://www.pwrusb.com/
编辑(再次):显然 您可以使用一些 USB 集线器来做到这一点。 这篇文章建议Linksys USB2HUB4 是一款可以使用的产品。
编辑(再次):显然有很多类似的问题,但似乎没有任何更有用的答案:
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:
大多数 USB 转串口或 USB 转 RS232 10 美元转换器都支持硬件握手。使用其中之一作为单通道数字 io。
将驱动继电器的晶体管连接到转换器板上的 DTR,并使用转换器驱动器命令 DTR ON/OFF。
2N7002 是一个很好用的晶体管(实际上是 FET),因为它可以在 3V 电压下工作,并且不需要任何电阻。
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.