#define PIR_PIN GPIO_NUM_4
Once the sensor is wired, detecting motion is as simple as reading a digital input. The following Arduino sketch demonstrates the basic principle:
To ensure reliable operation, the HW416B PIR sensor should be installed:
The datasheet gives you nothing. Here is practical, better code for both Arduino and ESP32 (with deep sleep for battery life). hw416b pir sensor datasheet better
TechRecipes Staff Difficulty: Beginner
HW416B PIR Sensor Datasheet: Understanding Your Motion Detector The HW416B PIR sensor
The stock fresnel lens is cheap plastic. You can the lens with a universal PIR lens (e.g., from a KC7783R) to achieve the claimed 7 meters. Also, the sensor is less sensitive to motion moving directly toward it versus moving across its field of view. #define PIR_PIN GPIO_NUM_4 Once the sensor is wired,
Most "datasheets" show a blurry image. Here is the clear pinout:
Sets how long the output stays HIGH after detecting motion, ranging from ~5 seconds to ~5 minutes. 4. Trigger Modes: Improved Functionality
| Symbol | Parameter | Min | Typ | Max | Unit | |--------|-----------|-----|-----|-----|------| | VCC | Operating voltage | 3.0 | 5.0 | 5.5 | V | | ICC | Quiescent current | 45 | 55 | 100 | µA | | VOH | Output high level | VCC-0.5 | VCC-0.3 | - | V | | VOL | Output low level | - | 0.2 | 0.5 | V | | TH | Delay time (fixed mode) | 2.5 | 3 | 3.5 | sec | | TH | Delay time (adjustable) | 0.3 | - | 500 | sec | | TLO | Lockout time (after trigger) | 1.5 | 2 | 2.5 | sec | | D | Detection distance (with stock lens) | 3 | 5 | 7 | meters | Most "datasheets" show a blurry image
Stop guessing the pinout. Here is the verified electrical data for the HW-416B:
Turning this clockwise increases the distance at which the sensor can trigger.