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. if (val == HIGH)
  17. {
  18. // check if the input is HIGH
  19. digitalWrite(ledPin, HIGH); // turn LED ON
  20. playTone(300, 160);
  21. delay(150);
  22. if (pirState == LOW)
  23. {
  24. // we have just turned on
  25. Serial.println("Motion detected!"); // We only want to print on the output change, not state
  26. pirState = HIGH;
  27. }
  28. }
  29. else
  30. {
  31. digitalWrite(ledPin, LOW); // turn LED OFF
  32. playTone(0, 0);
  33. delay(300);
  34. if (pirState == HIGH)
  35. {
  36. // we have just turned off
  37. Serial.println("Motion ended!");
  38. // We only want to print on the output change, not state
  39. pirState = LOW;
  40. }
  41. }
  42. }
  43. // duration in mSecs, frequency in hertz
  44. void playTone(long duration, int freq)
  45. {
  46. duration *= 1000;
  47. int period = (1.0 / freq) * 1000000;
  48. long elapsed_time = 0;
  49. while (elapsed_time < duration)
  50. {
  51. digitalWrite(pinSpeaker, HIGH);
  52. delayMicroseconds(period / 2);
  53. digitalWrite(pinSpeaker, LOW);
  54. delayMicroseconds(period / 2);
  55. elapsed_time += (period);
  56. }
  57. }
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: