PIR Discovery
So, here is the issue: I would like to have a PIR connected so that when motion is detected, the clock comes on.
All good so far. in the main program loop I can check to see if the status of the I/O from the PIR has changed since the last iteration and if it has – great, turn the clock on.
In another test I can see if the clock has been on any more than the last time it was triggered plus the desired delay time and if it has, then turn it off, still all good.
Given that the PIR is not something that I want sticking out of the front of the clock, it needs to be located remotely and plugged in via a suitable connector. This is where the fun starts.
The PIR output is LOW when stable and goes HIGH when triggered, that I can test for, lovely. But, what if the thing is not plugged in? The measured state of the I/O may not be HIGH, it may not even be LOW, how can we be sure the thing will ever switch on?
Simples, set the I/O to have the internal pullup resistor enabled. In that way, no PIR connected, it reads high, PIR connected and activated by movement, it still reads HIGH, PIR connected and no movement detected, it reads low and the clock can be shut down.
Another lesson learnt.
Recent Comments