I use a Pi3 Model B as a home alarm. For this reason, I use 11 of the GPIOs as inputs connected to reed switches (and a couple more with similar circuitry connected to 12V PIRs -)

The diagram for each GPIO is the following :

enter image description here

I use NO reed switches and when a door is open, the GPIO detects logic 1 (3V3).

I generally use relatively long cables (5-15 meters), shielded/grounded.

The alarm works relatively well, although sometimes I get some faulty indications (drops from 1 to 0) when I turn on/off some electrical equipment in the house which I am trying to mitigate (perhaps problem with the house grounding).

With the current circuitry, I use 4K7 resistors as pullups. The 1K resistor is used for protection in case I accidentally set it the GPIO as OUTPUT.

I am currently upgrading the alarm (basically replacing the perforated board I used with a PCB one) so my question is the following :

  • Should I use 1K and 4K7 resistors or should I use different values? While testing I used 1K and 10K resistors but I read somewhere that for long wiring I should prefer to use 4K7 or even 2K2 instead of 1K. So in practice I used 4K7. I suppose that this, compared to the 10K, increases the current flowing when the reed switch is closed. (The cabling's resistance is max a couple of Ohms).

Is there a reason to prefer 10K or 2K2 over 4K7? [list=]If I use 2K2, the current per GPIO will be 1,5mA. So 11 GPIOs will draw approx. 16.5mA. I guess it is fine, isn't it?[/list] [list]If I use 10K, the current per GPIO will be 0,33mA. So 11 GPIOs will draw approx. 4mA.[/list] [list]With 4K7, the current per GPIO will be 0,7mA. So 11 GPIOs draw approx. 7,7mA.[/list]

Theoretically, I could use 10K but with such current and circuitry, are there any drawbacks due to the small current flow when the reed switch is off (doors closed). Is this current flow indeed small? Additionally, any drawbacks concerning noise/interference, though the cables are shielded?

I aim to use again 4K7 but thought I'd ask just to hear some other opinions...

  • Would you elaborate on why you need this kind of connection? In line of theory you could just have a reed and be done with it. You're using the top GPIO as input/sense, the middle with 4K7 as driver. Why are you not just taking advantage of pulls?
    – MaxDZ8
    Commented Mar 23, 2020 at 7:59

2 Answers 2


I think the use of the 4.7K resistor is not sufficient to overcome the antenna effect due to the long wire to the reed switch. That's why it picks up interference from other electrical or electronic devices in the area.

You're really only limited by the capacity of the reed switch circuit and the output of the 3.3V GPIO output. Instead of getting 3.3V from the GPIO pin, why not get it from the power supply? That way you free up the GPIO pin in case you need it and can use a lower resistance value on the reed switch circuit.

I'd suggest a 1K and also put a capacitor, say 0.1 uF to ground near the input to the GPIO. That will both make the signal on the line harder to change and also reduce its susceptibility to interference.

  • Sorry, I made a mistake. I don't get the 3V3 out of a GPIO pin but out of the 3V3 pin of the RaspBerry.
    – Tassos Pan
    Commented Mar 23, 2020 at 19:57
  • I will add a capacitor between GPIO and ground. Should I also add a capacitor between 3V3 pin and ground too?
    – Tassos Pan
    Commented Mar 23, 2020 at 19:59
  • 1
    Bypass caps are almost always a good idea.
    – jwh20
    Commented Mar 23, 2020 at 20:22

This is not really a Pi question, but an electrical engineering question.

You are working in a noisy environment, so you should use good practice.

Connect to the Pi GND as common.

Take measures to reduce interference. E.g. use twisted pair (or shielded cable - but this is overkill, not to mention expensive) - a separate cable for each input, with the only common connection the GND at the Pi end.

Run wiring away from power cabling.

Use low impedance circuitry e.g. a low value pullup e.g. 1kΩ unless there is power limitation.

Adopt bounce suppression. This can be done in software and/or with capacitor to slow transitions. It won't matter if the Pi takes 1 sec to respond.

There are other isolation measures, but the above should suffice for most purposes.

NOTE the Pi can source ~800mA from 3.3V.

  • I am using shielded cables (grounded at one end) which I thought that would be sufficient. So you propose to use a 1K instead of a 4K7 or even 2K2. I will consider doing so. Thanks a lot
    – Tassos Pan
    Commented Mar 23, 2020 at 20:03

Your Answer

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

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