void loop() if (motionDetected) digitalWrite(LED_PIN, HIGH); Serial.println("Motion detected!"); motionDetected = false; lastMotionTime = millis();
For ESP32 deep sleep applications, connect HW416B OUT to a wake-up pin and use esp_sleep_enable_ext0_wakeup() . Use this better troubleshooting table when your HW416B misbehaves. hw416b pir sensor datasheet better
If you’ve landed on this page, you’re likely tired of digging through fragmented, incomplete, or poorly translated datasheets for the HW416B PIR sensor . You want a better resource—one that doesn’t just list pinouts but explains how to use this sensor reliably in real-world projects. You want a better resource—one that doesn’t just
volatile bool motionDetected = false; unsigned long lastMotionTime = 0; const unsigned long MOTION_HOLD_MS = 3000; // Match sensor's delay Also, the sensor is less sensitive to motion
attachInterrupt(digitalPinToInterrupt(PIR_PIN), motionISR, RISING);
HW416B OUT → 1kΩ resistor → Base of BC547 Emitter of BC547 → GND Collector → Relay coil negative terminal Relay coil positive → VCC (with flyback diode) The stock fresnel lens is cheap plastic. You can upgrade 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.