Ordered on weekdays before 14:00 = shipped the same day and delivered the next day in 98% of cases. Free returns 30-day reflection period 1-year warranty

Wiring diagram and code example

How to connect the PIR Sensor HC-SR501 Motion Sensor to an Arduino UNO or ESP32, with an example sketch you can upload straight away.

HC-SR501 Motion Detection with Arduino Uno

This project detects human motion using the HC-SR501 PIR sensor. When motion is detected, the sensor's output pin goes HIGH, lighting up the onboard LED and printing an alert to the Serial Monitor. Open the Serial Monitor at 115200 baud to view real-time motion status.

Wiring diagram: PIR Sensor HC-SR501 Motion Sensor on an Arduino UNO
Wiring diagram · Click to enlarge
Connection table: PIR Sensor HC-SR501 Motion Sensor on an Arduino UNO
Connection table · Click to enlarge
HC_SR501_Motion_Detection_with_Arduino_U.ino · compiled and verified
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : HC-SR501 Motion Detection with Arduino Uno
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : HC-SR501 PIR Motion Sensor
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// HC-SR501 PIR Motion Sensor Demo

const int PIR_PIN = 2;
const int LED_PIN = 13;

int lastState = LOW;

void setup() {
  pinMode(PIR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  
  Serial.begin(115200);
  Serial.println(F("HC-SR501 PIR Motion Sensor Initialized"));
  Serial.println(F("Warming up sensor (approx. 30-60 seconds)..."));
}

void loop() {
  int motionState = digitalRead(PIR_PIN);

  if (motionState != lastState) {
    if (motionState == HIGH) {
      digitalWrite(LED_PIN, HIGH);
      Serial.println(F("Motion detected!"));
    } else {
      digitalWrite(LED_PIN, LOW);
      Serial.println(F("Motion ended."));
    }
    lastState = motionState;
  }

  delay(100);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Motion Detection with HC-SR501 and ESP32

This project detects motion using an HC-SR501 PIR sensor. The sensor is powered from the 5V VIN pin, and a 1kΩ/2kΩ resistor voltage divider safely interfaces the sensor output with the ESP32 3.3V input. When motion is detected, the onboard LED illuminates and a notification is sent to the Serial Monitor.

Wiring diagram: PIR Sensor HC-SR501 Motion Sensor on an ESP32 DevKit V1
Wiring diagram · Click to enlarge
Connection table: PIR Sensor HC-SR501 Motion Sensor on an ESP32 DevKit V1
Connection table · Click to enlarge
Motion_Detection_with_HC_SR501_and_ESP32.ino · compiled and verified
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : Motion Detection with HC-SR501 and ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : HC-SR501 PIR Motion Sensor
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// HC-SR501 PIR Motion Sensor Demo
const int PIR_PIN = 13;      // Connected to HC-SR501 OUT via divider
const int LED_PIN = 2;       // Onboard LED

int lastState = LOW;

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  
  Serial.println("HC-SR501 Sensor warming up (approx. 30-60s)...");
  delay(2000);
  Serial.println("Ready to detect motion.");
}

void loop() {
  int motion = digitalRead(PIR_PIN);

  if (motion != lastState) {
    if (motion == HIGH) {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("Motion detected!");
    } else {
      digitalWrite(LED_PIN, LOW);
      Serial.println("Motion ended.");
    }
    lastState = motion;
  }

  delay(50);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

PIR Sensor HC-SR501 Motion Sensor

HC-SR501 PIR Motion Sensor is an infrared motion sensor with the following specifications:

– Detection distance: 3-7m.
– Delay: 5-200s
– Output voltage: 3.3V
- Operates on: 4.5-20V
– Detection angle: <140°.

HC-SR501 PIR Motion Sensor infrared PIR detects motion. When motion is detected, it gives a 3.3v signal on the output pin; the time is adjustable via potentiometer VR1. The detection distance is adjustable from 3-7 meters via potentiometer VR2.

 

  • PIR sensor
  • Adjustable time
  • Adjustable distance
  • Infrared detection
Playing loads the video from YouTube.

Why choose this product?

  • Motion detection – Gives a signal upon movement.
  • Adjustable delay – Time adjustable via potentiometer VR1.
  • Adjustable distance – Detection distance adjustable from 3-7 meters.
  • Wide power supply range – Works on 4.5-20V.
  • 3.3V output signal – Outputs 3.3V on the output pin.
Specifications
Output voltage3.3 V
Detection distance3-7 m
Delay5-200 s

Frequently bought together

Total: € 8,60

Reviews

★★★★★ 4,0/5 2 reviews
  • ★★★★★Ton PutVerified purchase

    Works perfectly and looks fantastic in a setup.

  • ★★★★★Brenon EjupovicVerified purchase

    Unfortunately, this version does not come with the jumpers to choose the H and L setting. But otherwise it works perfectly.

Write a review
Your rating

Shipping & returns

Shipping

  • Parcel with track & trace€ 7,70Within 24 hours
  • Pick up at PostNL location€ 7,40Within 24 hours
  • Letterbox parcel€ 3,70Within 2 business days
  • Letterbox parcel 24 hours€ 4,55Within 24 hours
  • Pick up in storeFree
All about shipping

Returns

Not satisfied? You have 30 days after delivery to return the product.

All about returns