GPIO Reed Switches

Active today
Viewed 30 times

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…

 New contributor

2 Answers


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 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.

 New contributor

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: