DESCRIPTION
The HC-SR501 PIR Motion Sensing Module uses the infrared radiation produced by body heat to detect motion at up to a distance of 21 feet.
OUR EVALUATION RESULTS:
These modules work very well with good sensitivity and are fun to play with as there are a lot of creative things that they can be used for such as home burglar sensing, trail game camera sensor, to waking up animated Halloween props when trick-or-treaters come up the sidewalk. Important Note: Due to their lack of body heat, it will not work well for establishing a Zombie perimeter alarm.
For breadboard use since these have caps and jumpers on the bottom, it can be handy to use a stackable type F/M header to plug the module header into and then insert that into the breadboard. That allows the sensor to sit up straight and gives access to the jumper and pots.
The program below uses a simple state machine to monitor the state of the sensor. Basically it just checks on the state of the sensor attached to pin 4 and does something if it sees that the state has changed. In this case, we are just turning an LED on/off that is connected to pin 5 and also sending a status update to the Serial Monitor window. This basic state machine technique allows the microcontroller to be off doing other things in-between checking on the sensor rather than using the more common Delay() type of technique between reading the sensor which blocks all other activity.
The LED is helpful as a visual indicator when wandering around to see how the detection works. As usual, you will need to insert a 220 ohm or so current limiting resistor between the Arduino and the LED to keep everyone happy.
HC-SR501 PIR Motion Sensor Module Test Program
/* HC-SR501 PIR Motion Sensor Module Test Basic code for monitoring the output of the sensor and reporting the results to the Serial Monitor and by turning an LED on/off. We hook the sensor pin up to pin 5 and the LED anode to pin 4. The LED cathode should go to ground via a current limiting resistor. */ int const SENSOR_PIN = 5; // Use any available digital pins int const LED_PIN = 4; int state = 0; // Current state of the sensor int lastState = 0; // Last state of the sensor //=============================================================================== // Initialization //=============================================================================== void setup() { pinMode (LED_PIN, OUTPUT); // Define LED pin as an output Serial.begin (9600); // Set output window comm rate } //=============================================================================== // Main //=============================================================================== void loop() { state = digitalRead (SENSOR_PIN); // Read the current state of the sensor if (state != lastState) // State has changed { digitalWrite(LED_PIN, state); // Update the LED with current state Serial.print ("Current State: "); // Printout new state Serial.println (state); lastState = state; // Remember last state we were in } }
The board has a 2 small holes that can be used for mounting if desired. An optional acrylic mounting bracket is available below.