Arduino MOTION DETECTOR PIR DSN-FIR800

Hello world! Today i made an example on how to build a simple pir motion detector/alarm using the DSN-FIR800. I will build one that sends a sms on detection with a gsm shield later.
The motion detector simply reads high or low value. High on detection LOW on no Detection.
You can add anything to it to let the motion sensor trigger something.. such as switching on or off relays to turn on or off a device when motion is detected.

Schematic:
arduino motion detector

Parts list:
Arduino uno or other.
Pir motion sensor, (DSN-FIR800)
Buzzer.
Led. Any color will do.
Jumper wires, MM/FF/MF

Code:

//Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
//This example code is written to show you how simple it is to build your own pir motion detector.
int calibrationTime = 30; //give yourself time to leave the room       

long unsigned int lowIn;         

long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 7;   
int ledPin = 8;
int buzPin = 6;
int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};
//              1    2    3    4    5    6    7    8    9    10   11   12   13   14
// You can add more tones but i added 14. Just fill in what tone you would like to use, @ void loop you see " tone(Buzzer, tones[12]); " below,  digitalWrite(Buzzer, HIGH);
// here you can change the tones by filling in a number between 1 and 14
void setup()
{
  
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);
  pinMode(buzPin, OUTPUT);
  for (int i = 0; i < buzPin; i++) 
    {
 }
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   
       digitalWrite(buzPin, HIGH);
       tone(buzPin, tones[1]);
       delay(100);
       digitalWrite(ledPin, LOW);   
       digitalWrite(buzPin, LOW);
       noTone(buzPin);
       delay(200);
       digitalWrite(ledPin, HIGH);   
       digitalWrite(buzPin, HIGH);
       tone(buzPin, tones[14]);
       delay(100);
        
        if(lockLow){  
         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);
       digitalWrite(buzPin, LOW);
       noTone(buzPin);

       if(takeLowTime){
        lowIn = millis();         
        takeLowTime = false;      
        }
    
       if(!lockLow && millis() - lowIn > pause){  
           
           lockLow = true;                        
           Serial.print("Motion stopped at ");   
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *