Introduction to the PIR motion sensor
We will use PIR Motion Sensor (Passive Infrared) to detect movement. We can use the PIR sensor for security If the sensor detects movement, we can sound an alarm. Another use for the PIR sensor is to automatically energize a light when detecting movement. If you wake up in the middle of the night, the sensor can detect movement, and automatically energize a light for you. Likewise, when the sensor is mounted to a robot, you can have the robot execute a subroutine when motion is detected.
We will take a look at the controls and wiring on the back of the module:
To wire the module, connect VCC to +5v. GND will connect to ground. In this example, connect the output to Pin 2. We use the potentiometers to set the time delay, and sensitivity. Typically, the sensor will be able to detect movement up to 20 feet away.
The connected circuit will look similar to this. Pin #13 is connected to the LED indicator.
Furthermore, we need some code to upload to the arduino processor to verify that our circuit is working. I’ve modified some code from the Arduino Playground that we can use to test the circuit. Up to the present time, the source code for this project is here. The only change I made was to the pin our output is connected to. In this example, the output of the PIR sensor is connected to Pin #2.
Upload and test the code
First of all, be sure you select the correct communication port in your arduino IDE, and upload the sketch. Next, wait 30 seconds while the sensor calibrates. Finally, you are ready to use your sensor. You will notice when movement occurs, the LED indicator will energize.
At this point, if no motion is detected during the pause setting, the LED indicator will shut off.
If you are having trouble with the sensor, try to adjust the sensitivity and time delay potentiometers which are located on the PIR sensor itself. Not to mention, you must check the connections themselves.
— Ricky Bryce