So I have two door sensors and two gate sensors (magnetic) on a raspberry pi. The problem is that they periodically trip without the doors/gates being opened so I assume I am picking up noise on the circuit (roughly once a week on the longest run, longer on the shorter runs). The sensors are wired directly to the pi and are being fed with 3.3v with a 4.7k pull down resistor. The runs are pretty long, up to 50', and I am just using some thermostat wire on two runs, and some old phone wire on the other two runs. To fix the problem i wrote some code which reads the sensors twice with a 0.3sec delay between the readings and the readings must be the same or it ignores the readings until its time to read again (in another 0.3seconds) which has resolved the issue.
My questions are:
1. Should I be fixing the wiring to prevent the noise (and how) or is the coding an acceptable solution? What is best practice?
2. If I wanted to track the noise, how would I do that or see it? My volt meter doesn't see the noise on the circuit when I measure voltage.
My questions are:
1. Should I be fixing the wiring to prevent the noise (and how) or is the coding an acceptable solution? What is best practice?
2. If I wanted to track the noise, how would I do that or see it? My volt meter doesn't see the noise on the circuit when I measure voltage.