Using a D1 mini to go to deep sleep and wake up when motion is detected. On boot a message is sent via MQTT to node-red.
- Wemos d1 mini
- PIR motion sensor type HC-SR505
- NPN transistor 2N222
- Diode (I didnt use this but if prefered)
- Capacitor 1µF
- 2x resistor 1kΩ
Please be careful with your wiring. For example that PIR sensor is not standard wiring the colored wires should however show you that the data pin goes to the transistor.
Also check your transistor pin outs the 2N222 would be positioned so that the flat top with writing is actually facing away from you.
So the idea here is that when the PIR data pin is triggered it will charge the capacitor enough to trigger the transistor which will cause an interrupt to wake the D! mini. The transistor will then be drained though the resistor to ground.
The d1 mini is a huge on power drain you will get about 1 day running it on batteries. I deployed this today running on 18650 battery and started logging the triggers so time will tell how long this will run.
This is placed in the main corridor to turn on a Philips light strip at night time for guidance to the bathroom
- On trigger wakes up.
- Connects to wifi
- Connects to mqtt broker
- Sends mqtt payload aka its topic and the number 1
- Goes back into deep sleep
Within Node-Red i catch the payload in a trigger to send true, the trigger then waits 5 minutes and then sends false. Then a little logic to determine the time and if within time set the light will either turn on or stay off.
The next plan is to make this sensor smarter. Adding a light sensor (LDR photo-resistor) But before adding this component I will be checking the power consumption for this schematic in a busy zone in the house.
Here is my working example. This is all soldered on a prototype board:
So after a few times in and out of the corridor there is a fatal flaw :-(. Its to slow for what I need. I need something to trigger straight away. Based on my findings it takes a few seconds to connect to the Wifi which is the issue. As in those 3-4 seconds I could just hit the switch making this not so smart….
So I think its now time to open up my Arduino mini’s and use a 433 MHz module as I think this may shave the time down to about 1 second. Of course I will need a receiver to receive and then send an MQTT message but that could serve as a hub not running on batteries and run in a loop so speed should be fine….. OK waiting for after the festive season for that project.