B4R Question ESP8266 + PIR Sensor - False Triggers Issue

Hypnos

Active Member
Licensed User
Longtime User
Hi Erel,

My project using a PIR Sensor connected to ESP8266 board but I got some false triggers issue just like some other people in the web :

http://www.esp8266.nu/forum/viewtopic.php?f=5&t=671


The following actions might help to solve the issue:
1. Put the ESP in 802.11G mode instead of 802.11N mode. [ wifi_set_phy_mode(PHY_MODE_11G) ]
2. Lower the ESP wifi output power to 10dBm [ system_phy_set_max_tpw(powervalue max 82)


But the problem is I don't know how to write inline C code, can you please help take a look for the following code and see what's wrong because I got some error during compile? [Error: 'system_phy_max_tpw' was not declared in this scope]

Thank you!

B4X:
#if C
void SetLowPower(B4R::Object* o) {
       system_phy_set_max_tpw(32);
}

void SetMode11G(B4R::Object* o) {
       wifi_set_phy_mode(PHY_MODE_11G);
}
#end if
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please don't limit your questions to a single member.

Try it with these includes:
B4X:
#If C
#include "c_types.h"
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"

#include "lwip/opt.h"
#include "lwip/err.h"
#include "lwip/dns.h"

void SetLowPower...
 
Upvote 0

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi,

I have also used these PIR sensors and do not get any false positives.

But my setting is quite different :
- the ESP is most of the time in deepsleep mode or "Off"
- the PIR sensor output (3.3V) is directly tied to the CH-PD pin of the ESP and thus "wakes up" the ESP as soon as there is an alarm and powers it Off after alarm

The only drawback (in fact for me an advantage !) is that you have to tune the PIR trigger duration to more than the delay needed by ESP to wake up, boot, establish Wifi STA connection, and send the alarm.
1 minute is safe for all this.

The advantages are :
- low power consumption (only the PIR is powered --> 10mA)
- real time detection
- but quite long period to avoid "re trigger" and sending of alarm (once alarm sent and PIR activated, the ESP will be powered but is DeepSleep)
 
Upvote 0

Hypnos

Active Member
Licensed User
Longtime User
Hi Freedom2000,

My ESP also running some other tasks so I can't change it to deepsleep mode : (

The false positives issue really so strange as sometimes I got few triggers per day but sometimes I got so many... (I don't have any issue if I use the same PIR in Raspberry PI or UNO board.)

Hope that the "lower the WIFI power" can really solve the problem.
 
Upvote 0

Hypnos

Active Member
Licensed User
Longtime User
Thanks Erel for your code, but I got the following error during the compile:

B4X:
sketch\b4r_main.cpp.o:(.text._ZN8b4r_main8_connectEh+0x8): undefined reference to `system_phy_set_max_tpw(unsigned char)'
sketch\b4r_main.cpp.o: In function `b4r_main::_connect(unsigned char)':
sketch/b4r_main.cpp:55: undefined reference to `system_phy_set_max_tpw(unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1

And here is my code, anyone have idea what's wrong on my code? Thank you!

B4X:
Private Sub Connect(u As Byte)
    Log ("Connected to network, IP Address:")
    Log (wifi.LocalIp)
 
    RunNative("SetPower", Null)
End Sub



#if C
#include "c_types.h"
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"

#include "lwip/opt.h"
#include "lwip/err.h"
#include "lwip/dns.h"

void SetPower(B4R::Object* o) {
    system_phy_set_max_tpw(32);
}

#end if
 
Last edited:
Upvote 0

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi Freedom2000,
Hope that the "lower the WIFI power" can really solve the problem.

I am afraid that it only will be a workaround...

I have been playing with ESP for more than one year now. These devices are really great and so cheap. But they suffer with some "unstabilities" and need to be rebooted from time to time.
The idea of having ESP sleeping really prevents these unstabilities as the ESP is in "fresh boot condition" when it needs to "be there" :)

Furthermore, being off, the wifi antenna is also off which is good for the health...
 
Upvote 0

derez

Expert
Licensed User
Longtime User
I have the same false alarms. I added the power function but get the following error:
Compiling & deploying Ino project (WeMos D1 R2 & mini - COM5) Error

sketch\b4r_main.cpp.o:(.text._ZN8b4r_main8_connectEh+0x24): undefined reference to `system_phy_set_max_tpw(unsigned char)'
sketch\b4r_main.cpp.o: In function `b4r_main::_connect(unsigned char)':
sketch/b4r_main.cpp:38: undefined reference to `system_phy_set_max_tpw(unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board WeMos D1 R2 & mini.

Trying to change the mode:
Compiling & deploying Ino project (WeMos D1 R2 & mini - COM5) Error

sketch\b4r_main.cpp.o:(.text._ZN8b4r_main8_connectEh+0x24): undefined reference to `wifi_set_phy_mode(phy_mode_t)'
sketch\b4r_main.cpp.o: In function `b4r_main::_connect(unsigned char)':
sketch/b4r_main.cpp:42: undefined reference to `wifi_set_phy_mode(phy_mode_t)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board WeMos D1 R2 & mini.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
I decided to use engineering instead of magic...
separated the sensor from the Wemos to about 1 meter, used a shielded wire for the sensor output with the shield grounded.
It works ! I don't get false alarms (at least for few hours).
 
Upvote 0

Hypnos

Active Member
Licensed User
Longtime User
I decided to use engineering instead of magic...
separated the sensor from the Wemos to about 1 meter, used a shielded wire for the sensor output with the shield grounded.
It works ! I don't get false alarms (at least for few hours).


Hi derez,

Sometimes I only got few false triggers a day, please let me know if you can got a stable result after a long run!

I ordered some Wemos mini already because I love the compact size and I want to create a very small box of motion detect unit using esp, it's sad if finally I can only separate the sensor with a wire : (
 
Upvote 0
Top