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
- int ledPin = 7;
- int inputPin = 5;
- int pirState = LOW;
- int val = 0;
- int pinSpeaker = 10;
- void setup()
- {
- pinMode(ledPin, OUTPUT);
- pinMode(inputPin, INPUT);
- pinMode(pinSpeaker, OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- val = digitalRead(inputPin);
-
- if (val == HIGH)
- {
-
- digitalWrite(ledPin, HIGH);
- playTone(300, 160);
- delay(150);
- if (pirState == LOW)
- {
-
- Serial.println("Motion detected!");
- pirState = HIGH;
- }
- }
- else
- {
- digitalWrite(ledPin, LOW);
- playTone(0, 0);
- delay(300);
-
- if (pirState == HIGH)
- {
-
- Serial.println("Motion ended!");
-
- pirState = LOW;
- }
- }
- }
-
- void playTone(long duration, int freq)
- {
- duration *= 1000;
- int period = (1.0 / freq) * 1000000;
- long elapsed_time = 0;
- while (elapsed_time < duration)
- {
- digitalWrite(pinSpeaker, HIGH);
- delayMicroseconds(period / 2);
- digitalWrite(pinSpeaker, LOW);
- delayMicroseconds(period / 2);
- elapsed_time += (period);
- }
- }
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: