0
\$\begingroup\$

Beginner Warning!

I am trying to automate lights and fan in my house with the help of a raspberry pi. I read couple of guides in the internet. I finished the basic circuit. Now I can control a relay with my pi remotely. If I connect the relay in Line, I will be able to control my light but for some reason i cant power my pi or relay I will not be to turn on my light

schematic

simulate this circuit – Schematic created using CircuitLab

Another solution is I will connect the switch directly to light and another line through relay. So if i turn on the switch my light works & if I enable the relay my light works. Will this work? or Will it damage my relay?

schematic

simulate this circuit

Here is the relay i am using

\$\endgroup\$
1
  • \$\begingroup\$ Can you post exactly what relay you are using? (In case it makes a difference.) \$\endgroup\$
    – bgp
    Mar 29, 2017 at 4:50

2 Answers 2

2
\$\begingroup\$

If I were doing this, I'd use a latching single pole double throw relay. Your wall switches are single pole double throws switches, as well. Connecting the switch and relay in line like the below image will allow the wall switch or relay to toggle the light, regardless of each other's state. Using a latching relay allows you to turn on the relay with the raspberry pi's digital output, then stop driving it, and it will hold it's state.

I may be overstepping myself here, as this may not be the functionality you're looking for. The circuit I've shown below is similar to how a room with two light switches is wired. Hitting either switch, regardless of the other switch's position, turns the light on or off. This can be extended to any number of switches, as well, so you could, if you really wanted to, have 100 raspberry pi all switching the same light on and off.

schematic

simulate this circuit – Schematic created using CircuitLab

Note: Any values you see in the diagram are placeholders. You'll need to choose the correct components yourself.

Edit: Removed the resistor after actually looking at the device linked to. Added a flyback diode to the relay to protect against transient spikes when the relay is de-energized. Add a comment if you don't understand what this is for.

You'll need to check the datasheet to see what's going on with the relay you linked. Chances are, there's an onboard relay driver, in which case the flyback diode is probably already present. Adding it at your pi's output won't make a difference. Also, as noted in the comments, a latching relay usually has separate set and reset coils, which are not present in this schematic. In the end, though, that's not important, as the relay you linked is not a latching relay. Have fun driving that pin all day.

\$\endgroup\$
3
  • \$\begingroup\$ A latching relay is a good suggestion but this circuit could be misleading. Most latching relays have two coils (for set and reset). Why is there a 100 Ohm resistor in series with the coil? Also be sure to include a flyback diode on the coil. \$\endgroup\$
    – AngeloQ
    Mar 29, 2017 at 11:22
  • \$\begingroup\$ Yeah, I didn't see a latching relay when I flipped through the options in the capture tool. The diode's a requirement, unless the poster wants to replace the pi every time he switches the lights on or off. I should have seen his "Beginner Warning" on the top of the question and been more explicit. As for the resistor, that can go. I had it in my mind that he may not have a relay with the correct coil voltage, so he'd need a resistor to drop some power. 100 ohms was the default. In reality, it'll probably be a 12V deal, so there's more circuitry required that's not being shown, here. \$\endgroup\$ Mar 30, 2017 at 0:17
  • \$\begingroup\$ Or a 3.3 V relay. Serves me right for not looking at his link. \$\endgroup\$ Mar 30, 2017 at 0:20
3
\$\begingroup\$

No, if it's a typical electromechanical relay, wiring a switch in parallel with the contacts will not damage it. But then if the switch is closed, of course the RPi wouldn't be able to turn it off. Maybe that's OK for your application, e.g. if that switch would only be used as backup.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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