Professional Documents
Culture Documents
com
Login
Home All Category About us Hiring Privacy
Location: Home » Arduino Kits » Arduino 16+1 Sensor kit » Arduino lesson – PIR Motion Sensor
CONTENT
1. Introduction
2. Preparations
Hardware
Software
3. About the PIR Motion sensor
Overview
Specifications
PIR Sensing Angle diagram
How Does it Work?
Sensitivity Adjustment
Delay Time Adjustment
Trigger Mode Selection Part
4. Examples
Circuit Diagram
Upload Sketch
Running Result
PIR Motion Sensor Control Relay
Circuit Diagram
Code Program
Running Result
Introduction
A passive infrared sensor (PIR Motion sensor) is an electronic sensor that measures infrared (IR) light radiating from obje
field of view. They are most often used in PIR-based motion detectors. So, it can detect motion based on changes in infrared
the environment. It is ideal to detect if a human has moved in or out of the sensor range. In this lesson we will learn how a PI
Sensor works and how to use it with the Arduino Board for detecting motion.
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 1/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
Preparations
HARDWARE
Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
PIR Motion sensor x 1
Relay x 1
Breadboard x 1
Jumpers
USB Cable x 1
PC x 1
SOFTWARE
Arduino IDE (version 1.6.4+)
OVERVIEW
PIR Motion Sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the se
range. They are small, inexpensive, low-power, easy to use and don’t wear out. For that reason they are commonly found in
appliances and gadgets used in homes or businesses. They are often referred to as PIR, “Passive Infrared”, “Pyroelectric”, o
motion” sensors.
Use this Arduino motion sensor to build burglar alarm systems, home automation systems, or any simple gadget that prevent
people from getting into your room!
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 2/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
SPECIFICATIONS
Working voltage: 4.5V to 20V
Output: High: 3.3V, Low: 0V
Detection angle: Approximately 120 degrees
Range: Adjustable, up to 7m
Trigger modes: L unrepeatable trigger / H repeatable trigger (default)
Dwell time: (Stay-ON time) adjustable between 5-300 Seconds. –– it can be further increased by increasing the value o
CY1-Timing capacitor on pin 4 of the IC
Operating Temperature: -20 – +80 Degrees C.
PCB Dimensions: 33x25mm, 14mm High not including the Lens; Lens: 11mm high, 23mmDiameter.
Weight: 6g
PIRs are basically made of a pyroelectric sensor (which you can see above as the round metal can with a rectangular crys
the center), which can detect levels of infrared radiation. Everything emits some low level radiation, and the hotter something
more radiation is emitted. The sensor in a motion detector is actually split in two halves. The reason for that is that we are loo
detect motion (change) not average IR levels. The two halves are wired up so that they cancel each other out. If one half see
or less IR radiation than the other, the output will swing high or low.
This sensor is then placed behind a multifaceted lens (a Fresnel lens) that “chops up” the view of the world into smaller cone
heightened visibility and intervening areas of lessened visibility thus widening the useful viewing /detection angle dramatically
Along with the pyroelectic sensor is a bunch of supporting circuitry, resistors and capacitors. It seems that most small hobbyis
sensors use the BISS0001 (“Micro Power PIR Motion Detector IC”), undoubtedly a very inexpensive chip. This chip tak
output of the sensor and does some minor processing on it to emit a digital output pulse from the analog sensor.
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 3/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
When the PIR motion sensor detects a person, it outputs a 5V signal to the Arduino. Thus, an interrupt on Arduino is triggere
define what the Arduino should do as it detects an intruder.
As mentioned, the adjustable range is from approximately 3 to 7 meters. The illustration below shows this adjustment. You
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 4/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
SENSITIVITY ADJUSTMENT
click to enlarge the illustration.
SINGLE TRIGGER – The time delay begins immediately when motion is first detected.
REPEATABLE TRIGGER – Each detected motion resets the time delay. Thus the time delay begins with the last moti
detected.
For Example:
Imagine you’re in the single trigger mode (see below) and your time delay is set 5 seconds.
The PIR will detect motion and set it high for 5 seconds.
After five seconds, the PIR will sets its output low for about 3 seconds.
During the three seconds, the PIR will not detect motion.
After three seconds, the PIR will detect motion again and detected motion will once again set the output high and the ou
remain on as dictated by the Delay Time adjustment and trigger mode selection.
Examples
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 5/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
Connection
Connecting PIR sensors to a microcontroller is really simple. The PIR acts as a digital output so all you need to do is listen fo
to flip high (detected) or low (not detected).
Power the PIR with 5V and connect ground to ground. Then connect the output to a digital pin. In this example we’ll use pin 2
Code Program
After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power L
(labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. The
up the following sketch onto your Arduino.
int ledPin = 13; // choose the pin for the LED int inputPin = 2; // choose the input pin (for PIR se
This code just keeps track of whether the input to pin 2 is high or low. It also tracks the state of the pin, so that it prints out a
message when motion has started and stopped.
Running Result
A few seconds after the upload finishes, have a look at your Arduino’s pin 13 LED. You can also open your serial monitor
the baud rate to 9600 bps, you may see the following:
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 6/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
The PIR sensor requires a couple seconds of motion-free activity, while it gets a “snapshot” of it’s viewing area. Try not to
until the pin 13 LED turns off, then wave your hands, jump in the air, go crazy!
You will also notice that there is a delay associated with the motion sensor after each detection. Depending on the sensor, yo
be able to adjust this delay.
Connection
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 7/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
The output pin of the sensor will be connected to pin number 2 on the Arduino Board and when an object will be detected the
number 3 will activate the relay module and the high voltage lamp will turn on. For more details how the relay module works,
check the sketch below.
Code Program
After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power L
(labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. The
up the following sketch onto your Arduino.
int ledPin = 13; // choose the pin for the LED int relayInput = 3; // choose the pin for the relay i
Here’s the Arduino Code for this example. It’s quite simple. We just need to define the PIR Sensor pin as input and the relay
output. Using the digitalRead() function we will read the output of the sensor and if its high or if an object is detected it will ac
the relay. For activating the relay module we will send a logic low as the relay input pin works inversely.
Running Result
A few seconds after the upload finishes, you will see as below:
Note that after powering the sensor module it needs about 20 – 60 seconds to “warm-up” in order to function properly. Now w
will put your hand in front of the sensor the relay will activate the lamp. But note that even if you move your hand constantly t
will turn off after the adjusted delay time is over because the PIR sensor is in “non-repeatable trigger” mode. If you change th
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 8/9
12/12/2019 Arduino lesson – PIR Motion Sensor « osoyoo.com
sensor with the jumper to the “repeatable trigger” mode and you constantly move the hand, the lamp will be constantly on as
and it will turn off after the movement is gone and the set delay time is over.
Keep in minds that if you are using high voltage in this example, so you should be very caution.
https://osoyoo.com/2017/07/27/arduino-lesson-pir-motion-sensor/ 9/9