McLighting icon indicating copy to clipboard operation
McLighting copied to clipboard

Integrated a Signal from PIR Sensor to switch on and off LED

Open Roemke opened this issue 5 years ago • 5 comments

Hi Tobias, I have extended the master branch to connect a small PIR Sensor and worked like the #button concept in the original master branch. It would be nice, if you could integrate it into your branch. If I misunderstood something on using git and the pull request, please excuse me, I'm not using it very often. Thanks for your work Karsten

Roemke avatar Oct 25 '18 08:10 Roemke

Hi @Roemke, thank you for your contribution. We'll se how we can integrate it into the software. I'll have to get some sensor first to try this out. Which sensor did you use?

Best regards Tobias

toblum avatar Oct 26 '18 19:10 toblum

Hi Tobias, I think the cheap ones are nearly the same, I took the following: HC-SR501 PIR from AZDelivery via the Amazon Shop. But you can simulate the behaviour without connecting a PIR. Just put 3.3V to D2 ( <=> PIR see a motion) and after that 0V to D2 which is equivalent to PIR switching off after an adjustable timer (Potentiomenter on PIR). The code is as follows: If the LED is switched on (eg by web interface) -> no reaction on PIR Signal If the LED is off -> PIR signal sets the LED on, like the normal button if the PIR sends Signal from HIGH to LOW after the LED is switched on by the PIR signal -> switch off the LED, so the LED will not be switched off by the PIR Sensor if I have switched it on by the webinterface This will be used (I hope from this afternoon) to use the LED stripe at a small "cabin" for bicycles in the garden. If you like to have some light in the garden use the Webinterface, this settings will not be influenced by the PIR Sensor. But if you have switched off the LED by the Webinterface you will have light if you come to the garden to put the bike into the small cabin. Maybe there are the following improvements possible:

  • reaction depends on the time of day
  • reaction depends on another sensor: light of environment

But maybe I will use another esp to have my sockets (230V) in the garden without voltage most of the time, I have done some experiments with the relais shield for the d1 mini.
Best regards and excuse my English I don't need it very often. Karsten

Roemke avatar Oct 27 '18 08:10 Roemke

My recommendation is to get a HC-SR505 over HC-SR501. In my experience, it has mediocre sensitivity to movement and is not effected by stary Infrared signal much. Only caveat is there is no adjustment knob for the timer or sensitively. Both HC-SR501 & 505 take 5V input and out signal is 3.3V, which means you can connect directly to any pin on ESP8266.

There is also cheap human detector, ie microwave detector (RCWL-0516) that can sense movement through wood and walls.

Only issue with this code or any digitalread() in a loop() is that it causes wdt reset without a delay in loop(). It takes time to get the reply back from digitalread(), and blocks the rest of the code until reply. This can be avoided by using interrupts, could we change that?

debsahu avatar Oct 27 '18 12:10 debsahu

Hi @debsahu , yes, I think it would be a better solution to use an interrupt. But I have nearly no experience in microcontroller programming, so I just use Tobias code as example to see how it's possible to write a program for the esp, and choose the way like the button is implemented. I have tested the stripe on a breadboard and have no wdt reset occuring. After that I soldered it and put it this afternoon in the garden, so far I can't see a problem. If I would take a HC-SR505 I need to care about the time. So I just play a little bit with the potentiometer and for my needs it's enough. If I build the hardware again, I will compare the different sensors before I buy one. But in the last week I have a little time and thought - just try it :-) Thanks for your hints Karsten

Roemke avatar Oct 27 '18 14:10 Roemke

Hi @debsahu , I have read a short article on interrupt handling on arduino / esp and adapted it to my project. I have put it in the branch PIRSensorInterrupt on my fork of Tobias project. Maybe you could read it, I have no time to test it in detail, but I think it should work in this way. Thanks for your time. Karsten

Roemke avatar Oct 27 '18 16:10 Roemke