0

i have an output pin connected to a magnetic reed switch. The pin mode is INPUT_PULLUP. When the switch is closed, it connects the pin to GND and drags the pin to a LOW reading. I check the state of the pin in the loop function. Occasionally the pin reads LOW when it shouldn't (the switch is not closed) - e.g. around once per second. What could cause this? The wire from the pin to the switch is about 1m long - could this be long enough to intermittently drag it down to a LOW? Also, it seems to happen much more when the air temperature is hotter.

Circuit summary: Pin (INPUT_PULLUP) -> Magnetic reed switch -> GND

asked Jan 7, 2017 at 10:46
0

1 Answer 1

3

My guess would be that you're getting noise interference on the line and it's too much for the Arduino's little internal pullup. Try adding an external pullup resistor - say 5k-10k (exact value is not critical).

answered Jan 7, 2017 at 11:21
2
  • Thanks, you are correct. I managed it through code. E.g i'm now taking 10 samples a second, and to change state it needs 10 consecutive samples to be the same reading. This has been working without fail now for days. I suspect noise can only pull the pin down briefly (nanoseconds?) Commented Jan 13, 2017 at 2:39
  • Yes it will be brief, but how frequent will depend upon where the interference is coming from - it could conceivably happen a lot. If that's working for you then it sounds like a reasonable workaround. Commented Jan 13, 2017 at 9:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.