WLED with two PIR set as a switch

Hello together,

thanks to the maintainers and the community for this great project!

I have recently finished my first project with WLED. It is a night light with motion sensor that is glued under the bed. It is an ESP32 NodeMCU with a SK6812 RGBW strip, powered by a 5V stepdown and a generic 12V 2A PSU that I had left over from an external hard drive.

I use 2 hc-sr501 PIR modules (on G0 and G4), which I use as switch (WLED v0.13.3). Both modules are set to repeat. So the light stays on until the person leaves the monitored area and after a timeout of about 5 seconds the LEDs dim off. However, I ran into a little problem that maybe you guys can help me with. It looks like a switch is triggered by the high edge and then waits until it goes low again. If at a time shortly after the first the other PIR is triggered by a person. But in the meantime the timeout of the other PIR is reached, the second PIR is already high, so the person must leave the area of the seconed PIR again for the set timeout time before this PIR can trigger again.

I have played around a bit with the button settings but unfortunately found no setting that fits. The button type “Switch” does work for me. The type “PIR” seems to be low active, but my module is high active.

Do you have an idea how to solve the problem most elegantly?

Find a new PIR or add a transistor to invert the output.

I guess this would not work. Since the transistor would invert the signal of the second Transistor all the time. It must be in the way that it is inverting the signal from PIR2 depending on signal from PIR1.

My electrical solution would be more like a capacitor to get the function of an logical OR element.
The case where I house the setup is already kinda full. I thought more of a software solution here.

It’s not 100% clear what your problem scenario is here.

Can you try and put this into a simple Truth Table format:
You have 2 inputs PIR1 and PIR2, that gives you 4 possible states:

PIR1	PIR2		Result
 L	     L	  	    State1
 L	     H		    State2
 H	     L		    State3
 H	     H		    State4

So for each of the 4 possible inputs, you get a different output that you want WLED to handle with a preset (or something).

The ESP needs the signal pulled to ground. That device doesn’t do that.

A simple OR gate would do the trick IMO. Just use CMOS and not TTL.

Hi sorry for the double post yesterday.

PIR1 PIR2 Result
L L LED off
L H LED on
H L LED on
H H LED on

Very Simple OR.

@tonyno
Hmm, signal ist 0V for off. This is a timing / race condtion issue


PIR1
High     ______________________
Low _____|                     |_________________________________
         ^                     ^
         |                     |--low edge triggerd      
         |-- high edge trigger

PIR2
High                   _____________________
Low __________________|                     |__________________
                      ^                     ^
                      |                     |--low edge triggerd     
                      |-- high edge trigger

LED currently
On     ________________________
Off____|                       |_________________________________

LED desired
On      ____________________________________
Off____|                                    |_________________________________

@blazoncek
Yes, I guess but there is no way to set this up in WLED? I have to put in a physical element?

Indeed you do. 4071 or 74HCx32 or anything similar.

1 Like

Thanks, I just ordered a 74HC32. I should still have a breadboard / Strip grid PCB lying around.

Be careful to use 3.3V logic only as input to ESP.
If necessary use voltage divider.

1 Like

Hi, Holur,

I have a very similar scenario but only one HC-SR501 which is listed as compatible. I am trying to set it in a way that PIR will trigger the light on, delay for 45sec-1 min and turn off. I can’t find any documentation about setting PIR. Mine is connected to GPIO16 and set as PIR on Button 0. Behavior is erratic, or I can’t understand the pattern.

Can you please advise how to set it up?

Thanks!

There is no special set-up needed.
If you are using HC-SR501 and use 3 pins at the edge in the middle of PCB, make sure you connect Vcc to +5V, GND to GND and IO to GPIO of choice (some are not good as they may be strapping pins, check ESP documentation).

To have greater control of how PIR behaves you may want to try binary with PIR sensor usermod.

Hello Holur,
I am trying to build something similar for my home to what you have done over here using WLED and sensors. Would you be able to share some information on how you went about this and may be some code on how you did this ?

Thank you
Navin.

Multi PIR sensor usermod is now available in beta 0.15.

where i can find multi PIR sensor usermod for 0.15?

Among other usermods. You need to compile yourself, though.

Hi,
where to define 2 PIR sensors in the code?

There?

#ifndef PIR_SENSOR_MAX_SENSORS
  #define PIR_SENSOR_MAX_SENSORS 1
#endif

…/0_15/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h