Search the Community
Showing results for tags 'pir sensor tutorial with arduino'.
Just before creating my next projects tutorial, which will be using a PIR sensor, I thought I might create a separate tutorial explaining the working of a PIR sensor. By doing that I will be able to keep my other tutorial short and to the point. So, without wasting time let’s discuss what is a PIR sensor and how we can use it in our project. Step 1: Basic What is a PIR sensor? PIR or "Passive Infra-Red" sensor is a "Pyroelectric IR Sensor" which generates energy when exposed to heat. Everything emits some low level of radiation, the hotter the object is, the more radiation is emitted. When a human or an animal (with IR radiation wavelength of 9.4µMeter) approaches the sensors range the sensor detects the heat in the form of infrared radiation. The sensor only detects the energy emitted by other objects and don't produce any, that's why the sensor is called a PIR or "Passive Infra-Red" sensor. These sensors are small, cheap, rugged, low-power and very easy to use. Step 2: Hardware For this tutorial we need: 1 x Breadboard 1 x Arduino Nano/UNO (Whatever is handy) 1 x PIR Sensor 1 x LED and a 220 ohm current limiting resistor to test the connectivity Few connecting cables A USB cable to upload the code to the Arduino & General Soldering Equipments Step 3: Architecture As we can see the sensor has two sides: 1. Top or the Sensor Side 2. Bottom or the Components Side The Top consist of a specially designed 'High-Density Polythene' cover called "Fresnel Lens". This lens focuses the infrared rays to the underlying 'Pyroelectric Sensor'. 9.4 µMeter infrared rays can easily pass through the polyethylene cover. The sensors sensitivity range between 6 to 7 meters (20 feet) and the detection angle is 110 degrees x 70 degrees. The actual sensor is inside a sealed metal can. The can basically protects the sensor from noise, temperature and humidity. There is a tiny window made of IR-transmissive material to allow the IR signals to reach the sensor. Behind this window are 'two' balanced PIR sensors. In idle state, both sensors detect the same amount of IR radiation. When a warm body passes by, it first intercepts one of the two sensors, causing a positive differential change between the two halves. And then, when it leaves the sensing area, the reverse happens, and the sensor generates a negative differential change. When the pulse changes or in other words the PIR sensor detects motion, the output pin changes to "digital high" or 3.3V. The bottom bit consists of a bunch of circuitry. Few of them are of our interest. - Most PIR sensors have 3-pins VCC, GND and OUT. VCC and GND are to power the module (Operating voltage: DC 5V to 20V). The OUTPUT pin is the one which communicates with the micro-controller by sending digital pulse high (3.3v) when a motion is detected and digital low (0v) when no motion is detected. The pin-outs may vary between modules so always triple-check the pin-outs. - The BISS0001 or the "Micro Power PIR Motion Detector IC" gets the output from the sensor and after doing some minor processing it produces the digital output. - The module has two potentiometers one to adjust the sensitivity (which is up to 7m) and the other to adjust the time for which the output signal should stay high when an object is detected (it ranges from 0.3s to 5 mins). - There are 3 more pins on this module with a jumper between them to select the trigger modes. > 1st one is called "non-repeatable trigger" - this one goes low as soon as the delay time is over. > 2nd one is called "repeatable trigger" - it stays high as long as the object is in the proximity and will turn off once the object is gone and the delay is over. I will be using this mode for this project. If you want to do a quick test before going ahead with this tutorial please follow the steps below. A testing is also a good idea to test the range and duration of sensing. Step 4: Connecting Without Arduino - Connect the VCC to the +5v rail of the breadboard - Connect the GND to the -ve rail - Connect the LED along with a 220 ohm resistor to the OUT pin of the sensor Now, when the sensor detects a motion, the output pin will go "high" and the LED will light up. Move back and forward to find out the sensing the range. Then to test the duration walk in front of the sensor and then walk away and use a stopwatch to find out how long the LED stayed on. You can adjust the time or sensitivity by adjusting the POTs on the board. Step 5: Connecting With Arduino Now, to do the same with Arduino connect the VCC of the PIR sensor to the 5v pin of Arduino. Then connect the OUTput pin to D13 and GND to the Ground pin of the Arduino. Now, connect the LED along with a 220 ohm resistor to the D2 pin of the Arduino. Thats it, now you just need to upload the code and test if everything works the way it should. You can replace the LED with a Buzzer (to raise an alarm when an object is detected) or a Relay to drive a high voltage circuit. To learn more about relays please have a look at my tutorial Number 4 - "Driving a Relay with an Arduino". https://www.instructables.com/id/Driving-a-Relay-W... Step 6: Code The code is very simple * Start by defining the pin number 2 and 13 as LED pin and PIR pin respectively * Then we need to define the pin modes. LED pin to be the OUTPUT pin and PIR pin to be the INPUT pin * Next we need to read the value of the PIR pin and see if it is HIGH * If the value is HIGH, then turn ON the LED otherwise turn it OFF Step 7: Areas of Application of PIR Sensors PIR sensors can be used to: * Automate Opening and Closing of Doors * Automate All Outdoor Lights * Automate Lights of Basement, Garden or Covered Parking Areas * Automate Lift Lobby or Common Staircases Lights * Detect Presence of Human and Raise an Alarm * Create a Smart Home Automation & Security System, and many more.... Step 8: Demo So, this is my setup for the testing of the PIR sensor. The sensor is hooked up to the breadboard and is sitting on the table. As I am in front of the sensor the LED is on. Now, lets do a quick test. Currently, the sensor is in its idle state. I am going to walk in front of the it to activate the sensor. Tada, the LED just turned on after detecting my presence. The light stays on as long as I am in the sensors proximity. OK, lets walk away and start my stop watch to see if it turns off after 5 seconds. Success, everything worked the way I wanted. Thanks again for watching this video! I hope it helps you. If you want to support me, you can subscribe to my channel and watch my other videos. Thanks, ca again in my next video.