Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Code

1 int buzzer = 11;

2 int sensor = 8;
3 int led = 13;
4 void setup()
5 {
6 pinMode(buzzer, OUTPUT);
7 pinMode(sensor, INPUT);
8 pinMode(led, OUTPUT);
9
10 digitalWrite(buzzer,LOW);
11 digitalWrite(sensor,LOW);
12
13 digitalWrite(led,LOW);
14

15 while(millis()<13000)
16 {
17 digitalWrite(led,HIGH);
18 delay(50);
19 digitalWrite(led,LOW);
20 delay(50);
21 }
22 digitalWrite(led,HIGH);
23
24 }
25

26 void loop()
27 {
28 if(digitalRead(sensor)==HIGH)
29 {
30 digitalWrite(buzzer,HIGH);
31 delay(3000);
32 digitalWrite(buzzer,LOW);
33 while(digitalRead(sensor)==HIGH);
34 }
35
36 }

view rawArduino_PIR_Sensor.ino hosted with ❤ by GitHub

NOTE:

VCC- VOLTAGE at Common Collector

VEE- Voltage at Common Emitter

IDE- Integrated Development Engineering

How PIR Sensor works?


PIR Sensors are complicated than most other sensors. PIR Motion Sensor may
seem simple when implemented as all you need to do is check for a HIGH signal
on the Digital Out Pin of the Sensor whenever motion is detected.

But, internally, there is a lot going on and the input and output of the sensor are
dependent on several variables.

The actual PIR Sensor i.e. the one which is covered with a lens, consists of two
slots and both these slots are made up of IR Sensitive materials. Under normal
condition where there is no movement in front of the sensor, both the slots in the
Sensor detect same amount of infrared radiation.

When there is movement in front of the sensor, like a human or a cat, their
radiation is interpreted by one of the slots first and the differential output between
the two slots becomes positive.

As the person moves away, the second slot detects the radiation and the
differential output will become negative. Based these output pulses, a motion is
detected.
Testing the PIR Sensor
Since the Digital Out Pin of the PIR Sensor is either HIGH or LOW based on the
movement detected, you can build a simple circuit to test the PIR Sensor.

The first circuit consists of a PIR Sensor and an LED. When the PIR Sensor
detects motions, the LED turns ON. The duration for which the LED is ON can be
adjusted with the help of Delay Adjust POT.

A similar PIR Sensor testing circuit is shown below but it consists of a buzzer. In
order to drive the buzzer, an NPN Transistor like BC547 or 2N2222 can be used.
The buzzer will be activated when the sensor detects any movement.  

  
Arduino PIR Sensor: PIR Motion Sensor using Arduino
Let us make a small Motion Sensor or Motion Detector project using Arduino and
PIR Sensor. In this project, the PIR Sensor detects any movement in front of it
and signals Arduino. Whenever any movement is detected, Arduino will activate
an alarm in the form of a Buzzer.

This circuit doesn’t implement a major design but gives an idea about how to
interface a PIR Sensor to Arduino and how to can we Arduino to use the data
from the PIR Sensor and drive other output devices or loads like relay, GSM
Module, buzzer etc.  
  Circuit Diagram

You might also like