I have had numerous false positive triggers of HC-SR501 on an ESP32, unfortunately my research has led me to some weird and wonderful solutions. From running it on 3.3V, soldering items to it, and reducing the Wifi band and tx power. On the latter, I am testing a build with some changes to do just that.
Research - HC-SR501 PIR - stop false positives? - Page 1 - Let's Control It
I solved this with the next solutions:
A: Used a 47uF and 102pF power decompling consensator soldered over the pir power connections at the ESP8266 side.
B: Put the ESP in 802.11G mode instead of 802.11N mode. I think the Rf spectrum will be less in G mode.
C: Put the ESP in wifi STA mode only.
D: Lower the ESP wifi output power to 10dBm.
In main.ino
//Reduce WiFi interference when using ESP32 using custom WiFi mode and tx power
# ifdef ESP32
// https://github.com/jnogues/ESP32-Long-Range-WiFi/issues/4
// Reset wifi protocol
if (esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR) != ESP_OK) {
Log.error(F("Failed to reset WifiMode." CR));
}
//https://github.com/espressif/arduino-esp32/search?q=WIFI_PROTOCOL_11G
//https://www.letscontrolit.com/forum/viewtopic.php?t=671&start=20
#ifdef WifiGMode
if (esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G) != ESP_OK) {
Log.error(F("Failed to change WifiMode." CR));
}
#endif
#ifdef WifiPower
WiFi.setTxPower(WifiPower);
#endif
# endif
In environments.ini
build_flags =
${env:esp32doitv1-aithinker-r01-sx1278.build_flags}
'-DHCSR501_LED_NOTIFY_GPIO=LED_BUILTIN'
'-DWifiGMode=true'
'-DWifiPower=WIFI_POWER_11dBm'
'-DZsensorHCSR501="HCSR501"'
'-DHCSR501_GPIO=13'
Anybody else with similar PIR problems and resolutions? I am now also logging the triggers to see if the code made any difference.