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
1 Answer 1
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).
-
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?)Shane– Shane2017年01月13日 02:39:59 +00:00Commented 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.Mark Smith– Mark Smith2017年01月13日 09:37:23 +00:00Commented Jan 13, 2017 at 9:37