When power is first applied to the HW-416-B, it requires anywhere from 30 to 60 seconds to learn the ambient infrared signature of the room. Any readings during this initialization window should be ignored.
To help me tailor any specific code variations or schematics, let me know:
void setup() pinMode(2, INPUT); Serial.begin(9600); void loop() if (digitalRead(2) == HIGH) Serial.println("Motion Detected!"); delay(100); Use code with caution. Copied to clipboard hw-416-b pir sensor datasheet
When using a Raspberry Pi with the RPi.GPIO library, the wiring is the same and the code is straightforward:
Users have reported some common issues, particularly with false triggers or the sensor not behaving properly. When power is first applied to the HW-416-B,
Connecting the HW-416-B to your microcontroller is straightforward.
The HW-416-B PIR sensor is an essential component for any hobbyist or engineer working with environmental awareness. Its adjustable sensitivity, wide operating voltage, and direct TTL output make it highly versatile for automatic lighting, security, and robotic applications. If you'd like, I can: Copied to clipboard When using a Raspberry Pi with the RPi
When motion is detected, the output goes HIGH. It returns to LOW after the delay time expires, even if the target is still moving.
This example prints "Motion detected!" whenever the sensor's output pin goes HIGH.
| Microcontroller | VCC on HW‑416‑B | OUT on HW‑416‑B | GND on HW‑416‑B | | :--- | :--- | :--- | :--- | | | 5 V | any digital pin (e.g., D2) | GND | | ESP8266 / ESP32 | 5 V (VIN) | any GPIO | GND | | Raspberry Pi | 5 V (pin 2) | GPIO (e.g., GPIO17, pin 11) | GND (pin 6) | | Raspberry Pi Pico | VBUS (5 V USB) | any GPIO | GND |
If the sensor is too sensitive, adjust the sensitivity potentiometer counter-clockwise. 8. Summary