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.
void setup() Serial.begin(9600); pinMode(PIR_PIN, INPUT); pinMode(LED_PIN, OUTPUT);
volatile bool motionDetected = false; unsigned long lastMotionTime = 0; const unsigned long MOTION_HOLD_MS = 3000; // Match sensor's delay hw416b pir sensor datasheet better
Serial.println("HW416B warm-up... wait 30 seconds"); delay(30000); // Mandatory per better datasheet Serial.println("Ready.");
| Feature | HW416B | HC-SR501 | |---------|--------|----------| | Size | Smaller (32mm x 24mm) | Larger (48mm x 28mm) | | Voltage range | 3.0–5.5V | 4.5–20V | | Quiescent current | ~55µA | ~100µA (but stable) | | Retriggering jumper | Yes (poorly labeled) | Yes (clearly labeled) | | Built-in regulator | No | Yes (AMS1117 3.3V) | | Best for | Battery-powered, compact devices | Arduino projects, higher voltage | HW416B OUT → 1kΩ resistor → Base of
Turn the right potentiometer fully clockwise, then back off 15 degrees. This prevents saturation. Part 4: HW416B vs. HC-SR501 – Which Datasheet is Better? If you're comparing sensors, here is the truth the datasheets won't tell you:
void loop() if (motionDetected) digitalWrite(LED_PIN, HIGH); Serial.println("Motion detected!"); motionDetected = false; lastMotionTime = millis(); void setup() Serial
void motionISR() motionDetected = true;