Skip to content
HC-SR501

Motion

Interfacing HC-SR501 Motion with ESP32 DevKit

What is the HC-SR501?

The HC-SR501 is a passive infrared (PIR) motion-sensor module. Its Fresnel lens focuses infrared changes onto a pyroelectric sensing element; when a warm body moves across the detection area, the module drives OUT HIGH. When the output hold time expires and no new trigger extends it, OUT returns LOW. It provides a digital motion event—not a distance, temperature, or image reading.

This reference covers the common HC-SR501 module, its three pins, trigger modes, adjustable delay and sensitivity, warm-up behavior, and practical design considerations. Module revisions and clone boards can differ, so confirm the labels and behavior of your own board.

The common HC-SR501 module has VCC, OUT and GND. Use the silkscreen on your actual board to confirm pin order.
The common HC-SR501 module has VCC, OUT and GND. Use the silkscreen on your actual board to confirm pin order.

Warning

**Power-up warm-up matters.** Allow roughly 30–60 seconds after applying power before judging the sensor. Initial triggers or unstable readings can occur while it settles. Do not use a PIR module as a safety-rated presence detector or the sole protection against hazardous motion.

HC-SR501 specifications

Sensor type
Passive infrared (PIR) motion detector
Supply
Common module range about 4.5–20 V DC; 5 V is a typical choice
Output
Digital active-HIGH; commonly about 3.3 V when HIGH
Detection range
Often up to around 5–7 m, depending on module, lens, environment and settings
Detection angle
Wide Fresnel-lens field of view; exact angle varies by lens and listing
Delay adjustment
Commonly several seconds to a few minutes; exact range varies by module
Trigger mode
Jumper-selectable single-trigger (L) or repeatable-trigger (H) on common boards
Interface
One digital output; no library or communication bus required

HC-SR501 pinout

PinConnectionPurpose
VCC5 V recommended for beginner circuitsModule power input; check the rating of your revision.
OUTDigital GPIO inputTypically LOW at idle and HIGH when motion is detected/held.
GNDBoard GNDCommon ground reference.

Swipe sideways to see every column →

The PIR element responds to changing infrared energy across zones of its Fresnel lens. It does not measure exact distance.
The PIR element responds to changing infrared energy across zones of its Fresnel lens. It does not measure exact distance.

How the HC-SR501 works

The lens divides the scene into multiple detection zones. As a person moves through those zones, the infrared pattern changes and the module's onboard electronics interpret the change as motion. A stationary person may stop producing repeated triggers even while still in view; PIR sensors are generally more responsive to movement across the field than to movement directly toward the lens.

The module's OUT pin is an active-HIGH digital signal. In a typical setup, LOW means idle and HIGH means the output timer is active. The HIGH period depends on the delay trim pot and trigger mode; it is not necessarily the exact time that a person remains in the sensing area.

Typical output behavior: OUT rises HIGH for a hold period after a motion event, then returns LOW unless retriggered.
Typical output behavior: OUT rises HIGH for a hold period after a motion event, then returns LOW unless retriggered.

Sensitivity, delay and trigger mode

  • Sensitivity trim pot: adjusts how readily the module detects movement and the practical detection range. Start at a moderate setting and tune it in the installed environment.
  • Time-delay trim pot: controls how long OUT stays HIGH after a trigger. The exact minimum and maximum vary among boards and clones.
  • Trigger jumper: common HC-SR501 boards label the modes H and L. In repeatable mode (H), new motion during the HIGH period can retrigger/extend the output. In single-trigger mode (L), additional movement during that period does not keep extending it in the same way. Verify the markings on your board.
  • Warm-up: allow about 30–60 seconds after power-up. Avoid adjusting multiple settings at once; change one variable, test, and record the result.
Illustrative timing only. Actual hold time and retrigger behavior depend on the module trim pots and jumper.
Illustrative timing only. Actual hold time and retrigger behavior depend on the module trim pots and jumper.

What you can build

  • Motion-activated light: use OUT as an input and control a properly rated driver; do not power a lamp or relay coil directly from the sensor output.
  • Room occupancy indicator: combine motion events with a timeout in software. A PIR alone cannot guarantee that a room is empty because a motionless person may not trigger it.
  • Doorway or corridor alert: use the output to log an event or sound a low-voltage buzzer through an appropriate driver.
  • Security prototype: add an alarm indicator or notification system, but treat the HC-SR501 as a hobby sensor, not a tamper-resistant security device.
  • Energy-saving automation: use motion to request lighting, then apply a separate software timeout and manual override.

Wiring and installation best practices

  1. Check the pin labels. Common modules often place VCC, OUT and GND along a three-pin header, but do not rely on a generic image if your board is laid out differently.
  2. Use a stable supply and common ground. Power the module from a suitable 5 V rail for typical Uno/ESP32 examples and connect GND to the controller's GND.
  3. Protect the GPIO. The common module output is about 3.3 V HIGH, which is suitable for many 3.3 V inputs, including ESP32. Measure or verify your particular module before connection; never assume an unknown clone has the same output circuit.
  4. Avoid heat and movement sources. Sunlight, heaters, hot air, moving curtains, and rapid temperature changes can cause false triggers. Mount the sensor firmly and aim the lens at the intended zone.
  5. Do not expect a rangefinder. The output says motion was detected; it does not identify the person, provide distance, or indicate direction.
  6. Drive loads correctly. Use a transistor/MOSFET, relay driver, or suitable interface circuit for external loads. Respect the controller's current and voltage limits.
  7. Handle mains safely. Keep mains wiring physically isolated from low-voltage electronics and use an appropriately enclosed, rated driver. If unsure, use a low-voltage demonstration load.

Troubleshooting

SymptomLikely causeWhat to check
OUT stays HIGH for a long timeDelay pot set high, repeatable mode, or repeated motionReduce delay carefully, check jumper mode, and test after leaving the field of view.
No detectionIncorrect pinout, inadequate supply, lens obstructed, or sensor not settledCheck VCC/GND, allow warm-up, remove obstructions, and walk across the sensing zones.
Triggers when nobody is presentHeating/airflow changes, sunlight, vibration, or an overly sensitive settingReposition away from HVAC vents and heat sources; lower sensitivity and retest.
Detects people inconsistentlyPerson moves directly toward sensor, poor mounting angle, or range setting too lowTest lateral movement across the lens zones and adjust mounting/sensitivity.
ESP32 input reads unpredictablyMissing common ground, long/noisy wires, or output voltage unlike expectedVerify ground and measure OUT HIGH; keep wiring short and confirm GPIO voltage safety.
Trigger occurs immediately after power-upNormal warm-up behavior on some modulesWait 30–60 seconds before evaluating steady-state operation.

Frequently asked questions

Does the HC-SR501 need an Arduino library? No. Read OUT with digitalRead(); the module performs its own PIR signal processing.

Is OUT 5 V? The common HC-SR501 output is typically around 3.3 V HIGH, but clones and variants can differ. Verify your module's output before connecting it to a 3.3 V-only GPIO.

Can an ESP32 read the output directly? Usually yes with a standard HC-SR501 module whose OUT is about 3.3 V HIGH. Connect grounds together and verify the actual output voltage. Do not connect an unknown 5 V logic output directly to an ESP32.

Why does it remain HIGH after motion stops? The delay pot sets an output hold time, and repeatable-trigger mode may extend that time if movement continues.

Can it detect a person through glass? Standard PIR sensors generally do not reliably detect body motion through ordinary glass because the relevant infrared wavelengths are blocked or altered.

Does the simulator reproduce real infrared sensing? No. The saved project lets you explore the wiring and code; its motion toggle represents a digital event and does not model optics, temperature, range, or timing.

Setting Up HC-SR501 with ESP32 DevKit

This guide reads the HC-SR501 digital output with GPIO27 on a classic ESP32 DevKit. The common module's OUT signal is typically about 3.3 V HIGH, which is generally suitable for ESP32 logic. Verify the output level of your particular board or clone before connecting it; ESP32 GPIOs are not 5 V tolerant.

Warning

**Voltage check:** the wiring below assumes OUT is about 3.3 V HIGH. If your module can output 5 V, use a suitable level shifter or divider before connecting it to an ESP32 GPIO. Connect module GND and ESP32 GND together.

VCC → 5V/VIN, OUT → GPIO27, GND → GND. Verify OUT voltage on your module.
VCC → 5V/VIN, OUT → GPIO27, GND → GND. Verify OUT voltage on your module.

Wiring: HC-SR501 to ESP32

Sensor pinESP32 connectionPurpose
VCC5V / VINModule power input.
OUTGPIO27Digital input; common output is around 3.3 V HIGH.
GNDGNDCommon ground.

Swipe sideways to see every column →

Try this circuit — SolderHub Simulator

The circuit is preloaded for exploration. Confirm simulator behavior against the real wiring and sensor datasheet before connecting hardware.

  1. 1Check your exact ESP32 pinout; this example uses GPIO27 on a classic ESP32 DevKit.
  2. 2Connect VCC to 5V/VIN, OUT to GPIO27 and GND to GND.
  3. 3Verify that OUT is 3.3 V-safe before connecting it to the GPIO; level-shift if needed.
  4. 4Upload the sketch using the correct ESP32 board target and port.
  5. 5Open Serial Monitor at 115200 baud and allow 30–60 seconds for warm-up.
  6. 6Walk across the lens field of view and check the serial output.
C++

Expected behavior

The Serial Monitor reports Motion detected while OUT is HIGH and No motion while LOW. GPIO2 is a common onboard LED pin, but LED wiring varies by ESP32 board; change LED_PIN or remove the LED lines if needed.

Troubleshooting

  • GPIO reads erratically: check common ground, power stability and the actual OUT voltage; do not feed 5 V into the GPIO.
  • Output stays HIGH: check the delay setting and jumper, then wait for the hold period to end.
  • No detection: allow warm-up, verify the pinout and try lateral movement across the lens zones.
  • GPIO27 unavailable: select a safe GPIO on your specific ESP32 variant and update PIR_PIN.

FAQ

Do I need a pull-up? Normally not; the common HC-SR501 has a driven digital output, unlike the open-collector A3144.

Can ESP32 read OUT directly? Usually, if the module output is about 3.3 V HIGH. Verify the actual module before wiring.

Is GPIO27 available on all ESP32 boards? No; pin availability differs by family and module.

Related Components

Related Guides & Projects