Many beginners think that output pin of HC-SR501 PIR sensor changes from LOW to HIGH when motion is detected, and changes from HIGH to LOW when motion is stopped.
In fact, That is one of the working modes of the motion sensor, but this mode is the most common-used mode for beginners.
However, in some cases, it does NOT work like that. How can we solve it?
The answer is to check the setting on the HC-SR501 PIR motion sensor. The sensor has two potentiometers and one jumper that allows users to adjust the sensor's setting.
To make it work as described above, adjust the setting as below image:
For other operation modes of the motion sensor and how motion sensor work, see detail in Arduino - Motion sensor tutorial
Good luck!