Posts with «hc-sr501» label

PIR Sensor (Part 2)


In this tutorial we will connect our HC-SR501 PIR (movement) Sensor to an Arduino UNO. The PIR sensor will be powered by the Arduino and when movement is detected, the PIR sensor will send a signal to Digital Pin 2. The Arduino will respond to this signal by illuminating the LED attached to Pin 13.

PIR Sensor (Part 1) : Showed that this sensor can be used in isolation (without an Arduino). However, I will still demonstrate how you can attach this sensor to the Arduino so that we can move forward to more advanced objectives and concepts.


Video









Parts Required






Fritzing Sketch








Arduino Sketch




 1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*Simple PIR sketch: Written by ScottC, 19th Dec 2013

http://arduinobasics.blogspot.com/

----------------------------------------------------*/

void setup(){
pinMode(13,OUTPUT);
pinMode(2,INPUT);
}

void loop(){
digitalWrite(13,digitalRead(2));
}




The sketch above reads the signal coming in from the PIR sensor on Pin 2, and if it reads HIGH, it light up the LED attached to Pin 13. If it reads LOW, it will turn the LED off. This is all controlled by line 13 in the Arduino Sketch above.

The following table helps to identify the purpose of the potentiometers on the PIR sensor. Most people say they use trial and error. I will attempt to reduce the mystery of these components on the PIR board.


104 (Left) – Max



LED on = 20 sec
LED off = 3 sec

When you move the 104 labelled potentiometer all the way to the left (max position), the LED will remain on for 20 seconds after movement is detected. The 20 seconds is independent of the other potentiometer (105) setting. When the LED turns off, it will remain off for 3 seconds before the sensor will trigger again from any further movement.




104 (Right) – Min




LED on = 1 sec
LED off = 3 sec

When you move the 104 labelled potentiometer all the way to the right (min position), the LED will remain on for 1 second after movement is detected. When the LED turns off, it will remain off for 3 seconds before the sensor will trigger again from any further movement.




105 (Left) – Max




Most sensitive – Detects movement from over 10 steps away.

The 105 labelled potentiometer controls the sensitivity of the PIR sensor. When in the left position, the PIR sensor is most sensitive and small amounts of movement will trigger the sensor. It detected my movement (ie a single step to the left of right) from over 10 steps away from the sensor. I was very impressed.




105 (Right) – Min




Least sensitive: Need significant movement for sensor to trigger. Detects movement from about 4 steps away.

When the 105 labelled potentiometer is twisted to the right, the PIR sensor becomes a lot less sensitive. I needed to take much bigger steps to the left or right to trigger the sensor (about 3 times the size compared to the left position). It also had a lot more trouble detecting movement occurring further away. It only really started to detect my movement when I was about 4 steps away from it. 

My preferred combination was 104-Right (min) + 105-Left (max), which meant that the sensor would remain on for only a short period of time, and detect any subtle movements in the room. This combination is displayed below:




I have not tested to see how it performs over a very long period with this setting, and whether it would suffer from false positive readings, but that could easily be fixed by turning the 105 labelled potentiometer a bit more to the right.

PIR Sensor (Part 1)


PIR sensors are pyroelectric or “passive” infrared sensors which can be used to detect changes in infrared radiation levels. The sensor is split in half, and any significant difference in IR levels between the two sections of the sensor will cause the signal pin to swing HIGH or LOW. Hence it can be used as a motion detector when IR levels move across and trigger the sensor (eg. human movement across a room).
The potentiometers are used to adjust the amount of time the sensor remains “on” and “off” after being triggered.  Essentially the delay between triggered events.
Here are a couple of pictures of the PIR sensor.

   

The sensor used in this tutorial is HC-SR501 PIR sensor.
You can get more information about this sensor here.




Parts Required







Sketch

 













Video

 






 

Sketch Explanation

 

The sketch described above can be used to test the functionality of the PIR sensor. I had another one of these sensors in my kit, and could not get it to work, no matter what I tried. The sensor would blink continuously even when there was no movement in the room. However, I must warn you, this specific sensor has an initialisation sequence which will cause the LED to blink once or twice in a 30-60sec timeframe. It will then remain off until the sensor detects movement. The amount of time that the LED remains on (when movement is detected) is controlled by one of the potentiometers.

Therefore, you could have it so that the LED blinks quickly or slowly after movement is detected.
If you set it to remain off for a long time, the sensor may appear to be unresponsive to subsequent movement events. Getting the timing right is mostly done out of trial an error, but at least the board indicates which side is “min” and which side is “max”.
Have a look at the PIR picture above for the potentiometer positions/timings that I used in the video.




In a future tutorial, I will connect this sensor to the Arduino. But don’t worry. The sketch is just as easy. And then the real fun begins.

See PART 2 - Connecting a PIR to an Arduino




Thankyou

 

I would like to thank the following people who took time out to help me when I was having issues with this sensor:
  • Steven Wallace
  • Bobby Slater
  • Pop Gheorghe
  • Mike Barela
  • Winkle ink
  • Jonathan Mayer
  • Don Rideaux-Crenshaw
  • Ralf Kramer
  • Richard Freeman
It just shows how great the maker community is. Thanks again… I almost gave up on this one !