Stufin
Home Quick Cart Profile

HC-SR501 PIR Sensor (Passive Infrared Sensor) + IR Proximity Sensor

Buy Now on Stufin

Pin Configuration

  • HC-SR501 PIR Sensor (Passive Infrared Sensor) + IR Proximity Sensor Documentation
  • Pin Description:
  • The HC-SR501 PIR Sensor module has 3 pins for connection. Here's a detailed explanation of each pin:
  • VCC (Pin 1):
  • + Function: Power Supply
  • + Description: This pin is used to connect the positive voltage supply to the module. Typically, a voltage range of 4.5V to 20V can be used, but the recommended operating voltage is 5V.
  • + Connection: Connect to the positive terminal of the power source (e.g., a 5V pin on an Arduino board).
  • OUT (Pin 2):
  • + Function: Digital Output
  • + Description: This pin outputs a digital signal ( HIGH or LOW ) when the sensor detects motion or proximity. The output is an open-drain output, which means it can sink current but not source it.
  • + Connection: Connect to a digital input pin on a microcontroller (e.g., an Arduino board) to read the sensor's output.
  • GND (Pin 3):
  • + Function: Ground
  • + Description: This pin is used to connect the ground reference of the module to the system.
  • + Connection: Connect to the negative terminal of the power source (e.g., a GND pin on an Arduino board).
  • Connection Structure:
  • Here's a step-by-step guide to connect the HC-SR501 PIR Sensor module:
  • 1. Power Connection:
  • Connect the VCC pin (Pin 1) to the positive terminal of the power source (e.g., 5V pin on an Arduino board).
  • Connect the GND pin (Pin 3) to the negative terminal of the power source (e.g., GND pin on an Arduino board).
  • 2. Signal Connection:
  • Connect the OUT pin (Pin 2) to a digital input pin on a microcontroller (e.g., Arduino Uno's digital pin 2).
  • Important Notes:
  • The HC-SR501 PIR Sensor module has a built-in voltage regulator, so it can operate with a wide range of input voltages. However, it's recommended to use a stable 5V power supply for optimal performance.
  • The sensor module has a sensitivity adjustment potentiometer on the back, which can be used to adjust the detection range.
  • The module also has a time delay adjustment potentiometer on the back, which can be used to adjust the time delay between consecutive trigger events.
  • By following these instructions, you can properly connect the HC-SR501 PIR Sensor module to your project and start detecting motion and proximity.

Code Examples

HC-SR501 PIR Sensor (Passive Infrared Sensor) + IR Proximity Sensor Documentation
Overview
The HC-SR501 PIR Sensor is a low-power, low-cost sensor that detects infrared radiation, typically emitted by humans. It is widely used in various applications, including security systems, home automation, and robotics. This sensor combines a passive infrared (PIR) sensor with an infrared (IR) proximity sensor, allowing it to detect both motion and proximity.
Pinout and Connections
The HC-SR501 PIR Sensor has three pins:
VCC (Red wire): Connect to a 5V power supply
 GND (Black wire): Connect to the ground (GND) of the circuit
 OUT (Yellow wire): Connect to a digital input pin of a microcontroller or other device
Specifications
Operating voltage: 5V
 Current consumption: 65mA
 Detection range: Up to 7 meters (23 feet)
 Detection angle: 120
 Response time: 0.5 seconds
Code Examples
### Example 1: Basic Motion Detection using Arduino
This example demonstrates how to use the HC-SR501 PIR Sensor with an Arduino board to detect motion and toggle an LED.
```cpp
const int pirPin = 2;  // Define the PIR sensor pin
const int ledPin = 13;  // Define the LED pin
void setup() {
  pinMode(pirPin, INPUT);  // Set the PIR sensor pin as an input
  pinMode(ledPin, OUTPUT);  // Set the LED pin as an output
}
void loop() {
  int sensorState = digitalRead(pirPin);  // Read the PIR sensor state
if (sensorState == HIGH) {
    digitalWrite(ledPin, HIGH);  // Turn on the LED if motion is detected
  } else {
    digitalWrite(ledPin, LOW);  // Turn off the LED if no motion is detected
  }
  delay(100);
}
```
### Example 2: Proximity Detection using Raspberry Pi (Python)
This example demonstrates how to use the HC-SR501 PIR Sensor with a Raspberry Pi to detect proximity and print a message to the console.
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)  # Set the GPIO mode to BCM
pirPin = 17  # Define the PIR sensor pin
GPIO.setup(pirPin, GPIO.IN)  # Set the PIR sensor pin as an input
while True:
    if GPIO.input(pirPin) == GPIO.HIGH:
        print("Object detected!")
    else:
        print("No object detected")
    time.sleep(0.5)  # Wait for 0.5 seconds before checking again
```
Note: Make sure to connect the HC-SR501 PIR Sensor to the appropriate pins on your microcontroller or single-board computer, and adjust the code accordingly.