PIR Sensor Detecting Object Using Arduino

Introduction

Figure1: PIR Sensor
  • It is used to detect the human being moving around approximately 10m from sensor.
  • The actual range is between 5m to 12m.
  • It is of high sensitivity and low noise.
Parts Of List
  • Arduino Board
  • PIR Sensor
  • Buzzer
  • Bread Board
  • LED
  • Hookup wire
Connection To An Arduino Board
  • In the PIR sensor they have three pins.
  • The first pin can be connected to dc voltage range as 5v.
  • The second pin can be connected to the Arduino board 5 in digital pin.
LED
  • The anode(+) pin can be connected to the digital pin 7 to an Arduino board.
  • The cathode(-) pin can be connected to the Gnd to an Arduino board.
Buzzer
Figure 2: Buzzer

Connection
  • The red color wire can be connected to the digital pin 10 to the Arduino board.
  • The black color wire can be connected to the Gnd to the Arduino board.
  • We can connect both the wires in exchange.
Programming
  1. int ledPin = 7; // choose the pin for the LED    
  2. int inputPin = 5; // choose the input pin (for PIR sensor)    
  3. int pirState = LOW; // we start, assuming no motion detected    
  4. int val = 0; // variable for reading the pin status    
  5. int pinSpeaker = 10; //Set up a speaker on a PWM pin (digital 9, 10, or 11)    
  6. void setup()  
  7. {  
  8.     pinMode(ledPin, OUTPUT); // declare LED as output    
  9.     pinMode(inputPin, INPUT); // declare sensor as input    
  10.     pinMode(pinSpeaker, OUTPUT);  
  11.     Serial.begin(9600);  
  12. }  
  13. void loop()  
  14. {  
  15.     val = digitalRead(inputPin); // read input value    
  16.     
  17.     if (val == HIGH)  
  18.     {  
  19.         // check if the input is HIGH    
  20.         digitalWrite(ledPin, HIGH); // turn LED ON    
  21.         playTone(300, 160);  
  22.         delay(150);  
  23.         if (pirState == LOW)  
  24.         {   
  25.             // we have just turned on    
  26.             Serial.println("Motion detected!"); // We only want to print on the output change, not state    
  27.             pirState = HIGH;  
  28.         }  
  29.     }  
  30.     else  
  31.     {  
  32.         digitalWrite(ledPin, LOW); // turn LED OFF    
  33.         playTone(0, 0);  
  34.         delay(300);  
  35.         
  36.         if (pirState == HIGH)  
  37.         {  
  38.             // we have just turned off    
  39.             Serial.println("Motion ended!");  
  40.             // We only want to print on the output change, not state    
  41.             pirState = LOW;  
  42.         }  
  43.     }  
  44. }  
  45. // duration in mSecs, frequency in hertz    
  46. void playTone(long duration, int freq)  
  47. {  
  48.     duration *= 1000;  
  49.     int period = (1.0 / freq) * 1000000;  
  50.     long elapsed_time = 0;  
  51.     while (elapsed_time < duration)  
  52.     {  
  53.         digitalWrite(pinSpeaker, HIGH);  
  54.         delayMicroseconds(period / 2);  
  55.         digitalWrite(pinSpeaker, LOW);  
  56.         delayMicroseconds(period / 2);  
  57.         elapsed_time += (period);  
  58.     }  
  59. }  
Explanation
  • In this concept the PIR sensor can act as the night security alarm at a particular distance. For example, we kept things on the table. If anybody touches them then there is an alert that produce sound.
Programming Explanation
  • Play tone means the value of the buzzer when it produced the sound.
  • If the Led is on the buzzer produced the sound and they mention the value.
  • If the Led is off the buzzer can't produce the sound then they could not mention the value.
Application
  • All outdoor lights
  • Lift Lobby
  • Multi Apartment Complexes
  • Common staircases
  • For Basement or Covered Parking Area
  • Shopping Malls
  • For garden lights
Output

                                                Figure 3: Output
 
Read more articles on Arduino:
 

Up Next
    Ebook Download
    View all
    Learn
    View all