Thursday 8 November 2018

[Tutorial] Passive infrared (PIR) sensor with Arduino Uno

PIR sensor tutorial with Arduino Uno

1. Types

There are three types of PIR sensors with the different outlook to test: 
HC-SR501
Product Description: https://www.mpja.com/download/31227sc.pdf
UNO R3

2. Introduction

Pin Outs and Controls

The pin-outs and controls for this device are shown in the picture below and described in the following table.
HC SR501 Motion Detector Pin Outs
Pin or ControlFunction
Time Delay AdjustSets how long the output remains high after detecting motion. Anywhere from 5 seconds to 5 minutes.
Sensitivity AdjustSets the detection range.... from 3 meters to 7 meters
Trigger Selection JumperSet for single or repeatable triggers.
Ground pinGround input
Output PinLow when no motion is detected.. High when motion is detected. High is 3.3V
Power Pin5 to 20 VDC Supply input

Device Area of Detection

HC SR501 View Area

Adjustment

PIR Range (Sensitivity) 
HC SR501 Sensitivity Adjust

Time Delay

HC SR501 Time Delay Adjustment

Mode Selection


The trigger mode selection jumper allows you to select between single and repeatable triggers.  The effect of this jumper setting is to determine when the time delay begins.

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 motion detected.
HC SR501 Trigger Mode Selection
Examples of the difference between distinct mode selection
In this first example, the time delay is set to three seconds and the trigger mode is set to single.  As you can see in the illustration below,  the motion is not always detected.   In fact, there is a period of about six seconds where motion cannot be detected. 
HC SR501 Dance Floor 3 Sec Single
In the next example,  the time delay is still at three seconds and the trigger is set to repeatable.  In the illustration below, you can see that the time delay period is restarted.    However, after that three seconds, detection will still be blocked for three seconds. As I mentioned previously,  you could override the 3 second blocking period with some creative code,  but do give that consideration.  Some of the electronics you use may not like an on and then off jolt.  The three seconds allows for a little rest before starting back up.
HC SR501 Dance Floor 3 Sec Repeat

3. Arduino HC-SR501 Motion Sensor Tutorial

  • connection: it only requires three wires.
HC SR501 Arduino Tutorial Hook Up
  • sketch
The sketch simply turns on Your Arduino LED connected to Pin 13 whenever motion is detected. Be sure to beware of and somehow handle the 1 minute initialization in whatever application you develop.


// HC-SR501 Motion Detector

// Sample Sketch


int ledPin = 13;  // LED on Pin 13 of Arduino
int pirPin = 7; // Input for HC-S501

int pirValue; // Place to store read PIR Value

void setup() {
  
  pinMode(ledPin, OUTPUT);
  pinMode(pirPin, INPUT);
  digitalWrite(ledPin, LOW);
}

void loop() {

  pirValue = digitalRead(pirPin);
  digitalWrite(ledPin, pirValue);

}

Attention: no matter what modes, the delay time is at least 3-4 seconds.


More information refers to http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-sensor-tutorial/


No comments:

Post a Comment

[Research] Recurrent Neural Network (RNN)

1. Introduction As we all know, forward neural networks (FNN) have no connection between neurons in the same layer or in cross layers. Th...