0

members

Easy Basics: Project 026a PIR sensor HC - SR 501 or HC - SR 505 , LEDs - motion detection system

of Acoptex.com in UNO

Basics: Project 026a

Project name: PIR sensor HC - SR 501 or HC - SR 505, LEDs - motion detection system

Attachments: sketch1, sketch 2,

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Arduino IDE ( you can download it from here  )

3.Jumper cables

4. LED 2 pcs (colors - red,green)

5. Resistor 2 pcs (220 Ohm each)

6. Breadboard

7. PIR sensor HC - SR 501 or HC - SR 505 1 pc

General

We will learn about PIR sensor and how to connect PIR sensor and LEDs to Arduino board to make a simple motion detection system.

Understanding the PIR sensor

They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.

The PIR sensor itself has two slots in it, each slot is made of a special material that is sensitive to IR. The lens used here is not really doing much and so we see that the two slots can 'see' out past some distance (basically the sensitivity of the sensor). When the sensor is idle, both slots detect the same amount of IR, the ambient amount radiated from the room or walls or outdoors. When a warm body like a human or animal passes by, it first intercepts one half of the PIR sensor, which causes a positive differential change between the two halves. When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change. These change pulses are what is detected.

That’s where the name of the sensor comes from, a Passive Infra-Red sensor. And the term “passive” means that sensor is not using any energy for detecting purposes, it just works by detecting the energy given off by the other objects.

PIRs are basically made of a pyroelectric sensor (which you can see above as the round metal can with a rectangular crystal in the center), which can detect levels of infrared radiation. Everything emits some low level radiation, and the hotter something is, the more radiation is emitted. The sensor in a motion detector is actually split in two halves. The reason for that is that we are looking to detect motion (change) not average IR levels. The two halves are wired up so that they cancel each other out. If one half sees more or less IR radiation than the other, the output will swing high or low.

The module consists a specially designed cover named Fresnel lens, which focuses the infrared signals onto the pyroelectric sensor.

The module has three more pins with a jumper between two of them. These pins are for selecting the trigger modes. The first one is called “non-repeatable trigger” and works like this: when the sensor output is high and the delay time is over, the output will automatically change from high to low level. The other mode called “repeatable trigger” will keep the output high all the time until the detected object is present in sensor’s range.

The module has three more pins with a jumper between two of them. These pins are for selecting the trigger modes. The first one is called “non-repeatable trigger” and works like this: when the sensor output is high and the delay time is over, the output will automatically change from high to low level. The other mode called “repeatable trigger” will keep the output high all the time until the detected object is present in sensor’s range.

You can find a typical PIR sensor datasheet here.

Signals and connections of the PIR sensor

Most PIR modules have a 3-pin connection at the side or bottom. The pinout may vary between modules. One pin will be ground, another will be signal and the final one will be power. Power is usually 3-5VDC input but may be as high as 12V. Sometimes larger modules don't have direct output and instead just operate a relay in which case there is ground, power and the two switch connections.The output of some relays may be 'open collector' - that means it requires a pullup resistor. If you're not getting a variable output be sure to try attaching a 10K pullup between the signal and power pins. An easy way of prototyping with PIR sensors is to connect it to a breadboard since the connection port is 0.1" spacing. Some PIRs come with header on them already, the one's from adafruit have a straight 3-pin header on them for connecting a cable.

Signals and connections of LED

The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.

Build the circuit

Connecting PIR sensors to a microcontroller is really simple. The PIR acts as a digital output so all you need to do is listen for the pin to flip high (detected) or low (not detected).

Its likely that you'll want retriggering, so be sure to put the jumper in the H position!

Power the PIR sensor VCC with +5V and connect GND to ground. Then connect the output to a digital pin. In this project we'll use pin 8.

The following picture shows the needed connections with the Arduino Uno.

Code

It is very simple code for this project. We just need to define the PIR Sensor pin as input and the LEDs pins as output. Using the digitalRead() function we will read the output of the PIR sensor and if its high or if an object is detected it will switch on the red LED and sends the message to Serial monitor, green LED will be off. Green LED will be on and red LED will be off if nothing detected.

Step by Step instruction

  1. Open Arduino IDE.
  2. Plug your Adruino Uno board into your PC and select the correct board and com port
  3. Open up serial monitor and set your baud to 9600 baud
  4. Verify and upload the the sketch to your Adruino Uno board
  5. If the motion detected PIR sensor will switch on the red LED and sends the message to Serial monitor, green LED will be off. Green LED will be on and red LED will be off if nothing detected.
  6. Note that after powering the sensor module it needs about 20 – 60 seconds to “warm-up” in order to function properly. Now when you 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 the lamp will turn off after the adjusted delay time is over because the PIR sensor is in “non-repeatable trigger” mode. If you change the sensor with the jumper to the “repeatable trigger” mode and you constantly move the hand, the lamp will be constantly on as well and it will turn off after the movement is gone and the set delay time is over.

Summary

We have learnt about PIR sensor and how to connect PIR sensor and LEDs to Arduino board to make a simple motion detection system. 

Library:

  • No libraries required for this project

Sketch:

  • See attachments on the begining of this project description. 


Other projects of Acoptex.com
Easy Basics: Project 086d ESP-12E module, BME280 sensor - Web server of Acoptex.com in ESP8266 ESP-12 18-07-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 05-09-2017
Viewed: 1109 times