Electrical – How to get the state callback from a relay switch

electricalrelayswitch

We have made an automation module with relay connecting the mains and the raspberry pi. We are maintaining the state for the switch on our server. We have the raspberry pi connected to the device over internet which can control the switch state. The problem we are facing is that when we turn on or turn off the switch from the physical switch on the main we are not able to get the state for the switch(whether on or off)…. **is there any way to get the state from the physical switch to raspberry pi over relay*circuit connection*.

NOTE : I am a noob in electrical.

Best Answer

It's really easy. Given mains powered equipment, and wanting to detect if it is energized.

You get a common 5-volt wall-wart power supply, the kind you plug into the wall and it makes 5 volts. You plug that in, in a way that the wall-wart receives power if the equipment does. How you do that is up to you, follow the Electrical Code obviously.

The output of this 5VDC, you simply connect to a digital input of the Raspberry Pi. Either the digital input will sense 5 volts, or it will not. If it does not, then the equipment is not receiving power.

Add a high value pulldown resistor at the Pi so it definitely pulls the input down to zero when the supply is not running.

It's simple, bulletproof, and largely off the shelf.