0
\$\begingroup\$

I have a relay which I need to detect the state of (similar to this question but no current flow) and would like know what the easiest method would be to detect the state via USB and Raspberry-pi. I assume the simplest method would be to detect the resistance, but my lack of knowledge of what's available out there makes it hard to even know what it is that I'm looking for.

\$\endgroup\$
  • 1
    \$\begingroup\$ Lots of details needed: what is the voltage of the relay coil and is it AC or DC? What is the relay contacts switching? Are there extra relay contacts available? \$\endgroup\$ – DoxyLover May 14 '15 at 22:24
  • \$\begingroup\$ The Pi has GPIOs which can be used to detect the state of a relay contact, so why do you want to use USB? You say there is no current flow - does that mean the relay contacts are not connected to anything? (or if they are, what circuit are they connected to?). \$\endgroup\$ – Bruce Abbott May 14 '15 at 23:55
  • \$\begingroup\$ USB because I have a USB hub already setup where I need it and the GPIO would add additional wiring. The relay is 5v, but from an educational perspective, if it were a switch that only had an open and closed state, how what could be used to detect the state? Essentially a USB ohmmeter, but I'm not familiar with anything like that? \$\endgroup\$ – Travis May 15 '15 at 14:39
  • \$\begingroup\$ @BruceAbbott the relay isn't connected to anything. It's there only to signal a change in state. \$\endgroup\$ – Travis May 15 '15 at 14:49
2
\$\begingroup\$

A relay is effectively an electrically operated push-button, so you can use a similar circuit to detect relay contact closure as for a push-button being pressed.

Connect a resistor in series with the relay contacts and apply voltage to the circuit. When the relay contacts are open no current flows, so there will be no voltage across the resistor and full voltage across the contacts. When the contacts are closed they apply full voltage to the resistor and current flows (limited by the resistance) while voltage across the contacts drops to zero. This voltage change can easily be detected by digital logic.

The circuit can produce either a logic '1' or logic '0' when the relay closes, depending on the whether it switches to the positive or negative side of the supply voltage. Switching to ground may be safer and require fewer wires. The resistor then pulls the input voltage up (producing logic '1') when the relay contacts are open.

schematic

simulate this circuit – Schematic created using CircuitLab

The Raspberry Pi's GPIO port has pull-up resistors built in, so you would only need to connect two wires to the relay. Unfortunately it is not quite so simple for USB. You cannot connect relay contacts directly to it. USB is a complex serial protocol which requires an intelligent device to convert the voltage change into a signal that can be transmitted over USB.

You could make a special USB device just for your purpose (and write a device driver to interface with it) but it may be easier to just use an existing USB device which has general purpose I/O (eg. TTL serial or parallel adapter) or even take apart a USB mouse or joystick and connect the relay contacts across one of its buttons.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.