Making a cheap alarm with web notifications through IFTTT is relatively simple with a passive infrared motion sensor (PIR) such as HC-SR501 and an esp8266.
You can install a few of these and monitor your home or office (provided power and WiFi of course). Future expansions could include a SIM GPRS module for SMS alarm messages.
The HC-SR501 module is one of the most common sold for Arduino/IoT based installments. Here’s a nice blog post describing a lot of interesting things about this sensor: http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-sensor-tutorial/
Problem #1:
As most this kind of sensor requires 5v to work reliably. In 3.3v it is proven that gives false positives or no detection of movement. So in a setup with esp8266 (or a NodeMCU board like I used) you must have a 5v output just for the PIR sensor.
Thankfully someone has found a solution without modifying the sensor as most propose (this is tested for the sensor working in repeat mode). Studying the schematics it is shown that instead of connecting the 5v power to the standard VDC input you can connect 3.3v directly to the lower pin of the High/Low trigger selection pin. You can read about this in the following blog post https://techgurka.blogspot.gr/2013/05/cheap-pyroelectric-infrared-pir-motion.html
Problem #2:
Interference! PIR sensor acts crazy when in close proximity with esp8266/NodeMCU’s WiFi producing a lot of false alarms.
The solution is to put the WiFi of esp8266 to sleep until there is a movement trigger from the sensor with this code:
void stopWiFiAndSleep() { WiFi.disconnect(); WiFi.mode(WIFI_OFF); WiFi.forceSleepBegin(); delay(1); }
Problem solved!
As mentioned you’ll need an IFTTT account and a webhooks (former maker) key to use in the code. So each time PIR sensor detects motion esp8266 connects to WiFi and fires a webhook event. For example a Pushbullet notification in your phone.
The schematic connecting PIR with a NodeMCU is the following:
An ON/OFF switch is also added to stop sending the alarms when needed.
The code for the above setup is uploaded here: https://github.com/nikant/PIR-ESP-ALARM
regarding Problem #1: When powering a WeMos D1 Mini with 5V, I can power the PIR with the same 5V. If this means the PIR will output 5V as well, that’s ok since the ESP’s input pins are 5V tolerant.
LikeLike
Really cool implementation! two questions: 1) how quick is the communication to ifttt (from the motion itself to the notification)? and 2) how feasible do you thinkis a version of this device on battery?
Cheers,
Francesco
LikeLike
If IFTTT isn’t swarmed by a big number of requests the notification is withing 1-2 seconds. That all depends on the network you’re on, WiFi signal, communication of the esp8266 and the router. In my tests with an old router and not the best network with my ISP it’s still done with 1-2 seconds.
Of course a battery device is entirely possible. But I would suggest a circuit with a rechargeable battery that would take over when main power fails.
LikeLike
Thanks guy! I’m trying to ad ON/OFF switch via web interface to activate o deactivate remotely.
LikeLike
From a security point of view this could mean that anyone that could find access to your web interface could deactivate it.
LikeLike
you’re right. anyone connected to my wifi. other solutions? your phisical switch mean I’ve to remind to switch ON…
LikeLike
You could do the web version but add at least a basic http authentication: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino
LikeLike