HC-SR505 Mini PIR (Passive Infrared) Motion Sensor Documentation
The HC-SR505 is a popular, low-power, and high-sensitivity motion sensor module based on the Passive Infrared (PIR) technology. It is commonly used in various IoT applications, such as home automation, security systems, and robotics. This module is compact, easy to use, and provides a digital output signal when motion is detected.
VCC: 5V power supply
GND: Ground
OUT: Digital output signal (TTL level)
Operating voltage: 5V
Operating current: 10mA (typical)
Sensitivity: 7m (typical)
Detection angle: 120
Response time: 2.5s (typical)
Output signal: High (3.3V) when motion is detected, Low (0V) when no motion is detected
### Example 1: Basic Motion Detection with Arduino
This example demonstrates how to use the HC-SR505 motion sensor with an Arduino board to detect motion and trigger an LED.
```c
const int pirPin = 2; // Pin for PIR sensor output
const int ledPin = 13; // Pin for LED
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int pirState = digitalRead(pirPin);
if (pirState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED when motion is detected
} else {
digitalWrite(ledPin, LOW); // Turn off LED when no motion is detected
}
delay(50); // Wait 50ms before checking again
}
```
### Example 2: Motion Detection with Raspberry Pi (Python)
This example demonstrates how to use the HC-SR505 motion sensor with a Raspberry Pi board to detect motion and print a message to the console.
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
pir_pin = 17 # Pin for PIR sensor output
GPIO.setup(pir_pin, GPIO.IN)
while True:
pir_state = GPIO.input(pir_pin)
if pir_state:
print("Motion detected!")
else:
print("No motion detected.")
time.sleep(0.5) # Wait 0.5s before checking again
```
### Example 3: Motion Detection with ESP32 (MicroPython)
This example demonstrates how to use the HC-SR505 motion sensor with an ESP32 board to detect motion and send a notification over Wi-Fi using MicroPython.
```python
import machine
import time
import network
import urequests
pir_pin = machine.Pin(0, machine.Pin.IN)
wifi_sta = network.WLAN(network.STA_IF)
wifi_sta.active(True)
wifi_sta.connect("your_wifi_ssid", "your_wifi_password")
while True:
pir_state = pir_pin.value()
if pir_state:
urequests.get("http://your_notification_service.com/motion_detected")
print("Motion detected!")
else:
print("No motion detected.")
time.sleep_ms(500) # Wait 0.5s before checking again
```
Note: Make sure to adjust the pin numbers and Wi-Fi credentials according to your specific setup.