# Reed switch 3m away using a telephone cable (AWG 28) [closed]

I am a software engineer so my electrical engineering skills are very lacking. I have 6 questions total in this jumble of text that I am trying to solve. If there are general concepts of EE that I should know about to get me through these please help push me in the right direction. :)

I am trying to get my Pi Zero W to detect if my garage door is open or not. I have 2 reed switches (both can operate in NO and NC, so it all depends how I implement it). Pi is going to sit on top of my garage door opener so I need to run 2 sets of wires, one to each reed that is ~3m away, and one to the reed switch that is ~30cm away.

I am planning to recycle some old telephone cable that I managed to find the datasheet for the exact cable I am using and each cable (4 cables inside it, am planning to use one to go from pi to switch, and one to go from switch back to the pi, leaving the other two dormant) is 28 AWG. I measured the cable as it is (I think its about 5.5m at the moment, which a 3m run would be 3m up and 3m back so this is roughly accurate for the run of the long wire) and got a resistance of 2.5ohms.

I am unsure of a few things (well most things). Mainly, will this work, will this burn out a pi, or is this next to nothing and the GPIO pins will be fine (Question1)?

The reed switches I ordeded don't list anything regarding their resistance, can I assume its negligible (Question2)?

Reading online about similar setups people mentioned voltage drop and the pi not being able to detect the circuit as high. I tried to use this calculator (copper, 28 AWG, 3.3V, DC, single set of conductors, 6m) but I didn't know what my load was. Assuming worst case scenario, it was at max load, 0.05A, this calculator gives me a voltage drop of 0.13V. Assuming the max voltage for LOW is 0.8V, and min voltage for HIGH is 1.3V (source) then I don't have to worry about voltage drop being an issue (Question3)?

Wondering if my internal resistance of the cable is going to be a problem I found an ohms law calculator and plugged in my 3.3V, and 2.5ohms of resistance for the cable. And it told me my current is 1.32A. But Pi can only output 50mA total across GPIO pins. Am I reading this wrong based on my electrical engineering knowledge (Question4)? (I did one class in high school 16 years ago)

Am I right in thinking I run both wires from the 3V3 pin on the pi, to each of the switches and then back to the pi GPIO pins where I set them as input pins and then I can just detect if the pin is high or low (Question5)? Both switches will running as NO, so either one circuit least one circuit complete when the door is open or closed, and no circuit connected when the door is opening/closing. Or would it be best to set one as NC and one as NO so while the door is closed (I rarely leave, so it will be this most of the time, and when I open the door I don't keep it open for longer than a few minutes at a time) there is no complete circuit, one complete circuit while opening, and two complete circuits when opened (Question6)?

EDIT: regarding Question5, I just found this, based on this I now plan to have the code similar to how they have written it, but wire from the ground to the switch and then back to the other pin. Not from 3V3 power rail to the switch, as that may possibly kill the pi and no one wants that.

## 1 Answer

The resistance of the cable is irrelevant in this case. Telephone cable would be suitable.

The configuration of switch in http://elinux.org/RPi_GPIO_Interface_Circuits is the most appropriate. You could use internal pullup, but I would recommend using resistors. Either NO or NC is suitable, just adjust your logic to suit.

I recommend you select a pin with default pullup i.e. GPIO 2-8; (4-6 have no other predefined role; 2-3 have onboard 1.8kΩ pullup for use with I²C but can be used if you do not use I²C). NOTE these are BMC numbers, not physical pin numbers. See http://www.panu.it/raspberry/

I strongly recommend connecting your switches between Gnd and GPIO (as per the link above). Electrically it makes no difference, but is better practice.

Reed switches are notorious for contact bounce; this can be handled with hardware, but software is more reliable. Python has software debounce, but it is far more reliable to just check the switch state after a delay (I normally use 0.5s), particularly when, as in this case speed is not an issue.