Description
This is HC-SR501 IR Pyroelectric Infrared Motion Sensor Detector Module
PIR sensors are used to detect motion from pets/humanoids from about 7m away. This one has an adjustable delay before firing (approx 2-4 seconds), adjustable sensitivity.
- working voltage range :DC 4.5-20V
- Quiescent Current :50uA
- high output level 3.3 V / Low 0V
- Trigger L trigger can not be repeated / H repeated trigger
- circuit board dimensions :32 * 24 mm
- maximum 110 ° angle sensor 7.
- 7 m maximum sensing distance
Getting started with PIR Motion sensor
In this project you’re going to create a simple circuit with an Arduino and PIR motion sensor that can detect movement. An LED will light up when movement is detected.
Parts required
Connecting the Hardware
Assemble all the parts by following the schematics below.
CODES
Upload the following code
int led = 13; // the pin that the LED is atteched to
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds
if (state == LOW) {
Serial.println(“Motion detected!”);
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
if (state == HIGH){
Serial.println(“Motion stopped!”);
state = LOW; // update variable state to LOW
}
}
}
NOTE: IF you get stray ‘223’ errors The problem is with your “
and ”
characters. Replace them with ordinary quotes, "
, and you should be fine.