Mon Feb 06, 2023 11:01 pm
I'm using a HC-SR312 AM312 sensor. I switched to a new one to see if the sensor was the problem, but it behaved the same way. I'm using a Raspi 4. I started over with a clean SD card, and have only two other Python programs on it, neither of which involves 60 seconds in any way that I can see.
I took the PI in question away, and used a different PI to provide power and ground to the sensor and connected its output lead to a voltmeter. The sensor behaved properly: it detected motion and produced no highs in the absence of motion.
I then went back to the original PI and ran the code with pin 17 (the one I had the sensor output connected to) connected to the voltmeter. When I ran the code there were no highs to the voltmeter.
So it appears that neither the sensor nor the code is producing a high at pin 17. Yet when I assemble the original PI and sensor together and run the code, it takes a photo every 60 seconds!
The sensor is connected to the PI with three 12" hook-up wires. The case for the PI has heat sinks and a fan in it. The only pins in use are power and ground for the fan and for the sensor, and pin 17 for sensor output; a total of 5. I tried using a different pin for the sensor output, but that didn't change anything. I tried using 5v and 3.3v to power the sensor; no difference in behavior.
I then connected the original sensor to the original PI 4, but connected the sensor output pin to a voltmeter instead of GPIO 17. When I ran the code and watched the voltmeter, the sensor behaved as expected; i.e., the only time the voltmeter showed 3.3v was when there was motion at the sensor. Encouraged, I turned everything off, reconnected the sensor output pin to GPIO17 and ran the code. No more 60-second highs! Photos were taken only when there was motion at the sensor.
However, after taking the setup outside (temp ~35F) where I plan to use it, it started taking photos almost continuously. I brought it back in, set it up and it started taking photos exactly every 60 seconds again. I removed the output pin from pin 17 and connected it to a voltmeter as in the previous paragraph, but this time the voltmeter went high every 60 seconds. Finally I put the sensor output back on pin 17 and to my great surprise it started working properly.
It is very frustrating dealing with this intermittent, unexplainable situation. Anyone reading through all this must be convinced that I'm nuts, and I'm beginning to think that could explain everything...