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.
Detect open or closed circuit via USB sensor
raspberry pirelayresistancesensor
Related Solutions
In many home security systems they use magnet switches to detect the state of the door.
You could also use something like IR to see if a certain part of the door frame is blocking the light.
And one more option is to sense if the door is horizontal or vertical, basically you would mount it to the inside of the door, when it opens it would be horizontal and closed would be vertical. This is actually how most of the off-the-shelve generic sensors work.
If you have a particular method that you prefer I can give some specific sensor recommendations as well.
Edit: I missed that you said you wanted it 4 meters from the door. I am not sure if you just want this because you don't want to deal with wireless, but the IR method can also work in which you put something that reflects IR on the door and then have your sensor look to see if your IR beam has been reflected or not.
Some more additions:
If it were me, I would get something like this, there are lots of other brands and methods that are used. Buying sensors and wireless modules can be pretty expensive when bought in quantity 1 and probably wont be worth the cost over just buying the off the shelf method.
Now if it were me wanting to tackle a fun project, I would use an accelerometer attached to the inside of the door (could even be a board just Velcro'd to the inside of the door). The accelerometer doesn't need to be anything special, just something that when attached can detect acceleration in the down direction when the door is vertical and the down direction when the door is horizontal. It so happens that the force of gravity will show up on an accelerometer. I would then use an Xbee module to transmit the status to an xbee that is inside.
Realistically you don't need to transmit very much very often, you could put everything into sleep mode when ever you aren't reading and then once every minute or so wake up and transmit the current state. Because of how little the device is on it could easily run off of a battery for a decently long time.
There may be other, better, methods of detection, but when ever I do a "for fun" project I like using parts that I might use in other projects. It helps to grow the intellectual property that I have, which is useful for the future.
You say you have I would "have a slight knowledge in electronics!
So I recommend not using your phone vibrator to activate something like a solenoid to control mains electricity.
I recommend buying something which does the mains control.
Search for "home electricity control". You will find lots of products which can turn mains power on and off.
Search for "home electricity control wifi" and you will find products which can turn power on and off, and which can be contacted remotely via the internet.
Once you have control of the mains, and you still want to use your phone, then look at writing an app on that home phone, which talks locally to the mains-controller. If you have a smart phone, e.g. Android, iPhone, etc. then you should be able to write an app relatively easily (there is probably one available already).
Best Answer
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.
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.