I have a power connection going from a button outside of my house to the doorbell box. I want to take a branch of this wire, and connect it to a raspberry pi to detect the button being clicked.

The question is: is this possible? And if it is, how can I connect my 220V power as an "input" to my Pi? I'm very new with electronics and I'm just getting started.

  • Dont connect 220v to to your RPi, you are going to need either a Mechanical Relay or a Solid State Relay. A RPi cannot control or interface with 220v, without addons. – Vincent P Nov 6 '17 at 12:48
  • Search on "optocoupler" if you want a solid state relay, BUT this could be very dangerous if you do it wrong. Doing some research to learn theory is always good. You should NOT attempt to implement this if you're not 100% sure that you know what you're doing. (Not to mention, if applicable where you live, licensed.) – Brick Nov 6 '17 at 16:49

The statements "220V power" and "I'm very new with electronics" raise concerns.

The only responsible advice I can give to anyone who isn't a licensed electical contractor is DON'T.

Try something involving lower voltages first.

  • I was about to write here the usual 1M resistor solution but... Well in fact it is better not (the I'm very new with electronics part discourages this) – frarugi87 Nov 15 '17 at 9:32

There are various ways of doing this my my current favourite (and probably safest) involves a small piece of plastic tubing with a neon and series resistor (I use 330K) in one end with good separation from an LDR in the other end. All sealed up to prevent external light getting in (shrink tube and black paint can come in handy). When mains is applied to the neon end it lights and the LDR resistance goes low, which can be detected by the Pi. Safe Mains Detector

  • Which is pretty much what an "optocoupler" is (mentioned in the comments on the question). – larsks Nov 6 '17 at 17:28
  • Building on the comment by @larsks, I fail to see how this is "safest" compared to buying a solid state device from a reputable source. They are not that expensive. Especially for a beginner. – Brick Nov 6 '17 at 17:53
  • Simplicity and separation. An optocoupler will require additional components to rectify and reduce the mains meaning more circuit parts connected to high voltage. – Bra1n Nov 6 '17 at 18:41

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.