PIR Motion Sensor

Application à la détection de mouvement : camera de surveillance, économie d'énergie, ...

Parallax PIR Sensor

 * https://www.parallax.com/product/910-28027
 * https://www.parallax.com/sites/default/files/downloads/910-28027-PIR-Sensor-REV-A-Documentation-v1.4.pdf

3.3V

Sparkfun
3.3V with a little hack
 * https://www.sparkfun.com/products/13285

SEN-08630

 * http://www.sparkfun.com/products/8630
 * http://bildr.org/2011/06/pir_arduino/
 * http://dx.com/p/ir-infrared-motion-detection-sensor-module-dc-5v-20v-139624

SKU 139624 (HC-SR501)

 * http://dx.com/p/ir-infrared-motion-detection-sensor-module-dc-5v-20v-139624
 * http://blog.roman-mueller.ch/index.php/2013/01/26/hc-sr501-passive-infrared-sensor-with-arduino/
 * http://zygzax.com/2012/11/17/sensor-de-movimiento-pir-hc-sr501/?lang=en

''The HC-SR501 Module has three connection pins: +5v, OUT(3.3v) and GND; and two variable resistors for calibration (Ch1 and RL2).

Ch1: With this resistor, we can set the time that the output of the sensor will be active. One of the main limitations of this module is that the minimum time is about 3s. If we change the variable resistor to another of 100K, we can decrease the minimum time to approximately 0.5 s.

RL2: This variable resistor allows us to set the detection range, which could vary betwen 3-7m.''

Dimension: 3.2cm x 2.4cm x 1.8cm (approx) Infrared sensor with control circuit board The sensitivity and holding time can be adjusted Working Voltage Range: DC 4.5V- 20V Current drain:<60uA Voltage Output: High/Low level signal:3.3V TTL output Detection distance: 3--7M(can be adjusted) Detection range: <140° Delay time: 5-200S(can be adjusted, default 5s +-3%) Blockade time: 2.5 S (default) Trigger: L: Non-repeatable trigger H: Repeat Trigger (default) Work temperature:-20-+80°C Trigger Method: L unrepeatable trigger / H repeatable trigger

Code
For Arduino /* * ////////////////////////////////////////////////// * //making sense of the Parallax PIR sensor's output * ////////////////////////////////////////////////// * * Switches a LED according to the state of the sensors output pin. * Determines the beginning and end of continuous motion sequences. * * @author: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at * @date:  3. September 2006 * * kr1 (cleft) 2006 * released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license * http://creativecommons.org/licenses/by-nc-sa/2.0/de/ * * * The Parallax PIR Sensor is an easy to use digital infrared motion sensor module. * (http://www.parallax.com/detail.asp?product_id=555-28027) * * The sensor's output pin goes to HIGH if motion is present. * However, even if motion is present it goes to LOW from time to time, * which might give the impression no motion is present. * This program deals with this issue by ignoring LOW-phases shorter than a given time, * assuming continuous motion is present during these phases. *  */

///////////////////////////// //VARS //the time we give the sensor to calibrate (10-60 secs according to the datasheet) int calibrationTime = 30;

//the time when the sensor outputs a low impulse long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low //before we assume all motion has stopped long unsigned int pause = 5000;

boolean lockLow = true; boolean takeLowTime;

int pirPin = 7;   //the digital pin connected to the PIR sensor's output int ledPin = 13;

///////////////////////////// //SETUP void setup{ Serial.begin(9600); pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); digitalWrite(pirPin, LOW);

//give the sensor some time to calibrate Serial.print("calibrating sensor "); for(int i = 0; i < calibrationTime; i++){ Serial.print("."); delay(1000); }   Serial.println(" done"); Serial.println("SENSOR ACTIVE"); delay(50); }

//////////////////////////// //LOOP void loop{

if(digitalRead(pirPin) == HIGH){ digitalWrite(ledPin, HIGH);  //the led visualizes the sensors output pin state if(lockLow){ //makes sure we wait for a transition to LOW before any further output is made: lockLow = false; Serial.println("---"); Serial.print("motion detected at "); Serial.print(millis/1000); Serial.println(" sec"); delay(50); }                 takeLowTime = true; }

if(digitalRead(pirPin) == LOW){ digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state

if(takeLowTime){ lowIn = millis;         //save the time of the transition from high to LOW takeLowTime = false;      //make sure this is only done at the start of a LOW phase }      //if the sensor is low for more than the given pause, //we assume that no more motion is going to happen if(!lockLow && millis - lowIn > pause){ //makes sure this block of code is only executed again after //a new motion sequence has been detected lockLow = true; Serial.print("motion ended at ");     //output Serial.print((millis - pause)/1000); Serial.println(" sec"); delay(50); }      }  }

For Arduino Analog (3.3V pour Parallax) /* * ////////////////////////////////////////////////// * //making sense of the Parallax PIR sensor's output * ////////////////////////////////////////////////// * * Switches a LED according to the state of the sensors output pin. * Determines the beginning and end of continuous motion sequences. * * @author: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at * @date:  3. September 2006 * * kr1 (cleft) 2006 * released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license * http://creativecommons.org/licenses/by-nc-sa/2.0/de/ * * * The Parallax PIR Sensor is an easy to use digital infrared motion sensor module. * ( http://www.parallax.com/detail.asp?product_id=555-28027 ) * * The sensor's output pin goes to HIGH if motion is present. * However, even if motion is present it goes to LOW from time to time, * which might give the impression no motion is present. * This program deals with this issue by ignoring LOW-phases shorter than a given time, * assuming continuous motion is present during these phases. *  */

///////////////////////////// //VARS //the time we give the sensor to calibrate (10-60 secs according to the datasheet) int calibrationTime = 5;

//the time when the sensor outputs a low impulse long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low //before we assume all motion has stopped long unsigned int pause = 5000;

boolean lockLow = true; boolean takeLowTime;

int pirPin = A0;   //the digital pin connected to the PIR sensor's output int ledPin = 13;

///////////////////////////// //SETUP void setup{ Serial.begin(9600); //pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); //digitalWrite(pirPin, LOW);

//give the sensor some time to calibrate // Serial.print("calibrating sensor "); //   for(int i = 0; i < calibrationTime; i++){ //     Serial.print("."); //     delay(1000); //     } //    Serial.println(" done"); Serial.println("SENSOR ACTIVE"); delay(50); }

//////////////////////////// //LOOP void loop{ int val=analogRead(pirPin); //Serial.println(val); if(val > 1023/2){ digitalWrite(ledPin, HIGH);  //the led visualizes the sensors output pin state if(lockLow){ //makes sure we wait for a transition to LOW before any further output is made: lockLow = false; Serial.println("---"); Serial.print("motion detected at "); Serial.print(millis/1000); Serial.println(" sec"); delay(50); }                 takeLowTime = true; }

if(digitalRead(pirPin) == LOW){ digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state

if(takeLowTime){ lowIn = millis;         //save the time of the transition from high to LOW takeLowTime = false;      //make sure this is only done at the start of a LOW phase }      //if the sensor is low for more than the given pause, //we assume that no more motion is going to happen if(!lockLow && millis - lowIn > pause){ //makes sure this block of code is only executed again after //a new motion sequence has been detected lockLow = true; Serial.print("motion ended at ");     //output Serial.print((millis - pause)/1000); Serial.println(" sec"); delay(50); }      }  }

For MSP430 Launchpad (3.3V pour Parallax) /* * ////////////////////////////////////////////////// * //making sense of the Parallax PIR sensor's output * ////////////////////////////////////////////////// * * Switches a LED according to the state of the sensors output pin. * Determines the beginning and end of continuous motion sequences. * * @author: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at * @date:  3. September 2006 * * kr1 (cleft) 2006 * released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license * http://creativecommons.org/licenses/by-nc-sa/2.0/de/ * * * The Parallax PIR Sensor is an easy to use digital infrared motion sensor module. * ( http://www.parallax.com/detail.asp?product_id=555-28027 ) * * The sensor's output pin goes to HIGH if motion is present. * However, even if motion is present it goes to LOW from time to time, * which might give the impression no motion is present. * This program deals with this issue by ignoring LOW-phases shorter than a given time, * assuming continuous motion is present during these phases. *  */

///////////////////////////// //VARS //the time we give the sensor to calibrate (10-60 secs according to the datasheet) int calibrationTime = 30;

//the time when the sensor outputs a low impulse long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low //before we assume all motion has stopped long unsigned int pause = 5000;

boolean lockLow = true; boolean takeLowTime;

int pirPin = P1_7;   //the digital pin connected to the PIR sensor's output int ledPin = GREEN_LED;

///////////////////////////// //SETUP void setup{ Serial.begin(9600); pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); /* digitalWrite(pirPin, LOW);

//give the sensor some time to calibrate Serial.print("Calibrating Sensor "); for(int i = 0; i < calibrationTime; i++){ Serial.print("."); delay(1000); }   Serial.println(" done"); */   Serial.println("SENSOR ACTIVE"); delay(50); }

//////////////////////////// //LOOP void loop{

if(digitalRead(pirPin) == HIGH){ digitalWrite(ledPin, HIGH);  //the led visualizes the sensors output pin state if(lockLow){ //makes sure we wait for a transition to LOW before any further output is made: lockLow = false; Serial.println("---"); Serial.print("motion detected at "); Serial.print(millis/1000); Serial.println(" sec"); delay(50); }                 takeLowTime = true; }

if(digitalRead(pirPin) == LOW){ digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state

if(takeLowTime){ lowIn = millis;         //save the time of the transition from high to LOW takeLowTime = false;      //make sure this is only done at the start of a LOW phase }      //if the sensor is low for more than the given pause, //we assume that no more motion is going to happen if(!lockLow && millis - lowIn > pause){ //makes sure this block of code is only executed again after //a new motion sequence has been detected lockLow = true; Serial.print("motion ended at ");     //output Serial.print((millis - pause)/1000); Serial.println(" sec"); delay(50); }      }  }