Stufin
Home Quick Cart Profile

HCSR501 PIR Motion Sensor (Passive Infrared Sensor)

Buy Now on Stufin

Note

The HCSR501 PIR Motion Sensor module is a generic component, and its specifications may vary depending on the manufacturer and supplier. Be sure to verify the specifications with your supplier before using the module in your project.

Pin Configuration

  • HCSR501 PIR Motion Sensor (Passive Infrared Sensor) Pinout and Connection Guide
  • The HCSR501 PIR Motion Sensor is a popular and widely used IoT component for detecting motion and presence. It has three pins, which are explained below:
  • Pin 1: VCC (Power Supply Pin)
  • Pin Function: Provides power to the sensor
  • Pin Type: Input
  • Recommended Voltage: 5V (can operate from 3.3V to 20V)
  • Connection: Connect to a 5V power supply or a microcontroller's 5V output pin
  • Pin 2: OUT (Output Pin)
  • Pin Function: Provides a digital output signal when motion is detected
  • Pin Type: Output
  • Logic Level: High (H) when motion is detected, Low (L) when no motion is detected
  • Connection: Connect to a microcontroller's digital input pin or a relay module's input pin to trigger an action when motion is detected
  • Pin 3: GND (Ground Pin)
  • Pin Function: Provides a ground reference for the sensor
  • Pin Type: Input
  • Connection: Connect to a 0V (ground) point in the circuit or a microcontroller's GND pin
  • Connection Structure:
  • Here's a step-by-step guide to connect the HCSR501 PIR Motion Sensor:
  • 1. VCC Pin: Connect the VCC pin to a 5V power supply or a microcontroller's 5V output pin.
  • 2. GND Pin: Connect the GND pin to a 0V (ground) point in the circuit or a microcontroller's GND pin.
  • 3. OUT Pin: Connect the OUT pin to a microcontroller's digital input pin or a relay module's input pin.
  • Example Connection Diagram:
  • Suppose we want to connect the HCSR501 PIR Motion Sensor to an Arduino Uno microcontroller to trigger an LED when motion is detected.
  • VCC Pin Arduino Uno's 5V Pin
  • GND Pin Arduino Uno's GND Pin
  • OUT Pin Arduino Uno's Digital Pin 2 (or any other available digital input pin)
  • In your Arduino code, you can then use the `digitalRead()` function to read the state of the OUT pin and trigger the LED when motion is detected.
  • Remember to consult the datasheet and specifications of the HCSR501 PIR Motion Sensor and your microcontroller or relay module for more detailed information and precautions.

Code Examples

HCSR501 PIR Motion Sensor (Passive Infrared Sensor) Documentation
Overview
The HCSR501 PIR Motion Sensor is a low-cost, low-power passive infrared sensor module designed to detect motion and movement. It is commonly used in various IoT applications, such as home automation, security systems, and robotics. This sensor module is based on the BISS0001 micro-power PIR sensor IC and features a built-in voltage regulator, making it easy to interface with microcontrollers and other devices.
Pinout
The HCSR501 PIR Motion Sensor module has three pins:
| Pin | Description |
| --- | --- |
| VCC | Power supply (typically 5V) |
| OUT | Digital output (HIGH or LOW) |
| GND | Ground |
Operating Principle
The HCSR501 PIR Motion Sensor detects motion by sensing the infrared radiation emitted by objects. When a person or object enters the sensor's detection range, the sensor output goes HIGH. The detection range can be adjusted by adjusting the sensor's sensitivity and the distance between the sensor and the reflective surface.
Code Examples
### Example 1: Basic Motion Detection with Arduino
In this example, we will use the HCSR501 PIR Motion Sensor to detect motion and toggle an LED on and off.
```cpp
const int pirPin = 2;  // PIR sensor output pin
const int ledPin = 13;  // LED pin
void setup() {
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
}
void loop() {
  int pirState = digitalRead(pirPin);
  if (pirState == HIGH) {
    digitalWrite(ledPin, HIGH);  // Turn LED on if motion detected
  } else {
    digitalWrite(ledPin, LOW);  // Turn LED off if no motion detected
  }
  delay(50);
}
```
### Example 2: Motion Detection with Raspberry Pi (Python)
In this example, we will use the HCSR501 PIR Motion Sensor 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  # PIR sensor output pin
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(1)
```
### Example 3: Motion Detection with ESP32 (MicroPython)
In this example, we will use the HCSR501 PIR Motion Sensor to detect motion and send a message over Wi-Fi using the ESP32's built-in Wi-Fi capabilities.
```python
import machine
import network
import ubinascii
import urequests
pir_pin = 25  # PIR sensor output pin
pir = machine.Pin(pir_pin, machine.Pin.IN)
wifi = network.WLAN(network.STA_IF)
wifi.connect("your_wifi_ssid", "your_wifi_password")
while True:
    pir_state = pir.value()
    if pir_state:
        print("Motion detected!")
        urequests.post("https://api.example.com/motion", json={"detected": True})
    else:
        print("No motion detected.")
    time.sleep(1)
```
Note: In all examples, make sure to adjust the pin numbers and the sensor's sensitivity according to your specific setup and requirements. Additionally, ensure that the power supply to the sensor module is stable and within the recommended voltage range.