The code for out PIR circuit is found in the chapter11/hc-sr501.py file. Please review the source code before proceeding to get a broad understanding of what this file contains.
The HC-SR501 datasheet stipulates that the sensor needs around 1 minute after power-on to initialize and stabilize itself. If you try and use the sensor before it becomes stable, you may receive a few erroneous triggers when you start the program.
Run the hc-sr501.py file in a terminal. When the HC-SR501 detects movement, the program will print Triggered on the terminal, or Not Triggered when no movement is detected, as shown in the following output:
(venv) $ python hc-sr501.py
PLEASE NOTE - The HC-SR501 Needs 1 minute after power on to initialize itself.
Monitoring environment...
Press Control + C to Exit
Triggered.
Not Triggered.
... truncated ...
If your program is not responding as expected, try adjusting one or more of the Sensitivity...