How to use The Mini PIR Sensor Module
The mini PIR sensor module (HC-SR505) is a sensor that can detect motion through the use of infrared light. In this guide, we will be using the Mini PIR Sensor Module (HC-SR505) that is found in our shop.
Parts
Wiring Guide
Step 1: Connect the PIR sensor pins to the Arduino
Sensor | Arduino |
---|---|
+ | 5V |
S | Pin 3 |
- | GND |
Programming
Step 1: First of all, define the pin number that is connected to the signal output
int signalPin = 3;
Step 2: Start the serial monitor and activate the pin that is connected to the signal output
void setup(){
Serial.begin(9600);
pinMode(signalPin, INPUT);
}
Step 3: Write down some code that will print on the serial monitor whether the sensor senses movement or not
void loop(){
if(digitalRead(signalPin)==HIGH){
Serial.println("Movement detected");
}else{
Serial.println("Did not detect movement");
}
delay(1000);
}
Full Code
int signalPin = 3;
void setup(){
Serial.begin(9600);
pinMode(signalPin, INPUT);
}
void loop(){
if(digitalRead(signalPin)==HIGH){
Serial.println("Movement detected");
}else{
Serial.println("Did not detect movement");
}
delay(1000);
}
Output
Serial Monitor