Reed switch closed in 99.9% of time - how to setup


This might be a simple questions but it bothers me and I could not find an answer:

I have a simple reed switch, that is closed in normal state (door closed) and open when the door opens.
That mean in 99.9 % of the time the switch is closed.

Can I simply hook it up to a digital pin and VCC of the arduino (of course including the usual pull-down resistor) and have it read by the software (digital read)?

Or will I setup a situation where all the time a significant amount of ampere will flow (due to the closed circuit in 99.9% of the time)?
Is this setup smart?

any hints will be appreciated.

Best regards!

As long as you select your pull-down resistor to draw a current well below the maximum current rating for the I/O pins (e.g. the maxium is 40 mA, but I suggest getting it down to around 20 mA if you can), you shouldn't have any problems not matter how long the switch is closed.

If you activate internal pull-up resistor, minimum 20 k , than current 5 V / 20 k = 0.25 mA, of course reed switch should be wired between input and ground. If 0.25 mA is too much , than you can keep internal pull-up off all the time, than turn on when you read a status and turn off again.

where all the time a significant amount of ampere will flow

The current flowing is not a significant amount. Most people would say it is an insignificant amount.

Magician's suggestion about using the microprocessor's pull-up resistor is another good option.

Although, keeping it off most of the time is only an option if you are polling the input pin in a loop, either in the main loop (the code within the brackets following "loop()" in your sketch) or a dedicated function called by the main loop. This is a perfectly acceptable way to read the sensor, especially if monitoring the door is the main purpose of your device.

However, either permenantly enabling the pull-up resistor or using an external pull-up/pull-down resistor gives you an additional option, using an interrupt. In this case your sketch could be doing something else, but when the door is opened the Arduino stops and goes immediately to an interrupt service routine (ISR) to respond to the door being open in some way. Once the ISR has finished it goes back to doing what it was doing before. This allow your Arduino board to instantly know when the door is open while also accomplishing something else during the >90% of the time the door is closed.

Oh and don't mind Grumpy_Mike's attempts to live up to his forum name. :stuck_out_tongue:

Thanks for all your answers!

@Magician: I am not fully understanding your suggestion although I read about the internal pull-up resistor.
If I wire the reed switch between a pin set to input with activated pull-up and Ground on the other side: How Do I read the switch state?
Could you elaborate a bit more?

How Do I read the switch state?

Exactly the same as you read it now with a digitalRead()
The only difference is that you get a HIGH when the switch is not pressed and a LOW when it is pressed.

Read this:-

Thanks to everybody for sharing their advice!

It took me a few days to try it all out but now it works like a charm.