If your HW-416-B is triggering constantly without visible movement, check for the following environmental variables:
// PIR Sensor Pin const int pirPin = 2; // LED Pin const int ledPin = 13; void setup() pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); Serial.begin(9600); void loop() int pirState = digitalRead(pirPin); if (pirState == HIGH) digitalWrite(ledPin, HIGH); // Turn on LED if motion detected Serial.println("Motion Detected!"); else digitalWrite(ledPin, LOW); // Turn off LED Serial.println("Motion Ended"); delay(100); Use code with caution. 7. Troubleshooting and Tips
: Digital output signal. Transitions from 0V to 3.3V when motion is detected. GND : Common ground. 4. Key Features and Operation hw-416-b pir sensor datasheet
Are you triggering a specific ? (like a relay , buzzer , or smart home automation event )
+------------------------+ | Fresnel Lens | | (Top Side) | +------------------------+ | | | VCC OUT GND (4.5V- (Digital (Ground) 20V) 3.3V) Pin Descriptions If your HW-416-B is triggering constantly without visible
// Define Pin Allocations const int PIR_PIN = 2; // HW-416-B OUT pin connected to Digital Pin 2 const int LED_PIN = 13; // Onboard LED indicator int pirState = LOW; // We start assuming no motion detected int val = 0; // Variable for reading the pin status void setup() pinMode(PIR_PIN, INPUT); // Declare PIR sensor as input pinMode(LED_PIN, OUTPUT); // Declare LED as output Serial.begin(9600); Serial.println("Initializing HW-416-B PIR Sensor..."); delay(10000); // Warm-up delay for the sensor to stabilize Serial.println("Sensor Ready!"); void loop() val = digitalRead(PIR_PIN); // Read input value if (val == HIGH) // Check if the input is HIGH digitalWrite(LED_PIN, HIGH); // Turn LED ON if (pirState == LOW) // Motion just started Serial.println("Motion detected!"); pirState = HIGH; else digitalWrite(LED_PIN, LOW); // Turn LED OFF if (pirState == HIGH) // Motion just ended Serial.println("Motion ended."); pirState = LOW; Use code with caution. Troubleshooting and Best Practices
Adjusts how long the output pin remains "HIGH" after motion is detected. Clockwise increases the delay (up to 200 seconds); counter-clockwise decreases it (down to ~0.5 seconds). 4. Operational Modes (Jumper Settings) Transitions from 0V to 3
If you cannot find documentation specifically for the HW-416-B, the HC-SR501 datasheet serves as an excellent and accurate reference.
The optional photoresistor and thermistor ports on some HW-416 variants enable and temperature compensation for enhanced functionality. With a light sensor connected, the module can disable motion detection during bright daylight and reactivate in darkness to conserve energy.
If motion is detected continuously within the delay window, the internal timer resets, keeping the output HIGH until the target stops moving and the delay time elapses. 🔬 How the HW-416-B Works