PIR Sensor (Rev B)

Item code: 555-28027


What It Can Do

  • Detects motion of humans or animals from as far away as 30 feet
  • Silent operation for alarms, motion activated nightlights, holiday props
  • Automatically resets after period of inactivity

Passive infrared (PIR) sensors detect motion by comparing the amount of infrared radiation that reaches a pair of detectors. When the two detectors “see” different values, the sensor indicates it as movement of an object, such as a person or an animal. PIR sensors are often used in driveway security systems, which turn on a light (but only at night) when someone approaches the house.

The Parallax PIR Motion Sensor has a simple on/off output: when on, the sensor is detecting movement. When movement stops the output turns off (after a short delay). The output of the sensor can be directly connected to a microcontroller, and operates much like a switch. You can use the on/off condition to directly read the current status of the PIR sensor.

A selectable jumper on the sensor lets you set working distance:

  • L (for Long) position, the effective sensor distance is up to 30 feet. This increases the sensitivity of the sensor, which may also cause more false triggers.
  • S (for Short) position, the sensor distance is up to 15 feet.

For proper operation the sensor should be allowed to warm up for 20 to 60 seconds after first applying power. This lets the infrared detectors stabilize. The sensor output is not reliable until the sensor has warmed up.

This KickStart is for Rev B of the PIR Motion Sensor. Earlier versions of the sensor operate in a slightly different manner. Check the Parallax Web site for information on using earlier versions of the sensor.


Parts List

  • PIR Motion Sensor
  • BASIC Stamp  HomeWork Board, Propeller Board of Education, Propeller QuickStart, or Arduino Uno microcontroller
  • 22 gauge solid conductor hookup wire

Basic Wiring

  • Power requirements: 3 to 6 VDC: 12 mA @ 3 V, 23 mA @ 5 V
  • Single bit output: high (triggered) or low (no trigger)
  • Dimensions: 1.41 x 1.0 x 0.8 in (35.8 x 25.4  x 20.3 mm)

Program KickStarts

Each of the example programs display the current state of the PIR module in a terminal/debug window. A settling or “warm up” period is included at the start of each program. Once the sensor is ready, trigger it by waving your hand in front of the plastic dome.

Note: A red LED inside the dome will glow when the module is triggered. Simultaneously, the status of the module should change in the terminal/debug window. The sensor will remain triggered as long as there is continuous movement in front of it. Once motion stops, the sensor resets itself after approximately 10 seconds.

BASIC Stamp HomeWork Board

Download BASIC Stamp 2 code for the Parallax PIR Sensor

’ {$STAMP BS2}
’ {$PBASIC 2.5}

DEBUG "Warming up..."
PAUSE 20000 				’ PIR warm-up time
DEBUG CLS
DO
  DEBUG HOME, "IN0 = ", BIN1 IN0 	’ Display state of PIR sensor
  PAUSE 100 				’ Small Delay
LOOP 					’ Repeat Forever

Note: When this program is run, the BASIC Stamp Debug Terminal will automatically open.

Propeller BOE and Propeller QuickStart


Propeller BOE Wiring Diagram

 


Propeller QuickStart Wiring Diagram

Download Propeller Spin code for the Parallax PIR Sensor

OBJ

  pst : "Parallax Serial Terminal"    ’ Use Serial Terminal object

CON

  _clkmode = xtal1 + pll16x 	      ’ Set clock mode
  _xinfreq = 5_000_000
  
VAR

  byte state 			      ’ Variable for storing PIR output
  
PUB PIR 

  dira[0]~ 			      ’ Set pin 0 to input
  pst.start(115200) 		      ’ Start Terminal at 115200 baud
  pst.str (string("Warming up..."))
  waitcnt(clkfreq * 20 + cnt) 	      ’ PIR "warm-up" time
  pst.clear 			      ’ Clear the screen

  repeat
    state := ina[0] 		      ’ Save state of PIR Sensor
    pst.home 			      ’ Move cursor to upper left
    pst.str(string("IN0 = "))
    pst.bin(state, 1) 		      ’ Display results
    waitcnt(clkfreq/200 + cnt) 	      ’ Small delay

This program uses the Parallax Serial Terminal object library, which is included with the Propeller Tool software download.

To view the results of the demonstration, after uploading is complete run the Parallax Serial Terminal from the Run menu, or press F12. Momentarily depress the Reset button on the Propeller QuickStart board to restart the program.

Arduino Uno

Download Arduino Code for the Parallax PIR Sensor

void setup() {
  Serial.begin(9600);
  Serial.println("Warming up...");
  delay(20000);
}

void loop() {
  Serial.print("IN2 = ");
  Serial.println(digitalRead(2), DEC);
  delay(200);
}

Note: To view the results of the demonstration, after uploading is complete click the Serial Monitor icon in the Arduino IDE. This displays the Serial Monitor window. Momentarily depress the Reset button on the Arduino board to restart the sketch.


For More Information

Useful links: