PIR sensor alarm with esp8266 and IFTTT webhooks (maker)

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() {

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


update THE433: Home Automation

It was about time to somewhat clean the code, update the README with instructions and also provide a demo Android app for my THE433 Home Automation

It’s a self contained ESP8266 RF433 Interface to control RF sockets from afar (with your personal IP or a DDNS service). No need for external services and servers (no MQTT, right now I prefer it that way..) and its main feature is that you can set RF signals to fire in the future or repeat over time.

The updated with instructions code: https://github.com/nikant/THE433

and also in GitHub you’ll find the demo Android app made with MIT-App-Inventor-2: https://github.com/nikant/THE433/tree/master/THE433%20Control%20Android%20demo%20app

AfraidDDNS updater

With all the IoT devices around Arduino, esp8266 etc. a hostname is often needed. https://freedns.afraid.org/ offers DDNS subdomains that are updatable through a special URL.

So this is a simple function that does just that.

Simply place files “afraidddns.h” and “afraidddns.ino” use
#include "afraidddns.h"
in your main program and call updateAfraid(); when needed

code: https://github.com/nikant/AfraidDDNS

You will need your afraid.org subdomain hash which you can get by logging in https://freedns.afraid.org/dynamic/ and checking the URL at the bottom of the page where it says Direct URL.
i.e. h++ps://freedns.afraid.org/dynamic/update.php?VxxxxxxxxxxFDGxxxxxxxxxx1xxxxxRTTxxxxxESP8

THE433: Home Automation with ESP8266, NodeMCU

control 433MHz (compatible with Arduino libs) sockets/devices through web and time rules
ESP8266 RF433 Interface

(esp8266 + RF 433 transmitter + Arduino IDE)

This is a sketch for controlling RF remote control sockets or relays that operate at the 433MHz frequency and are compatible with the Arduino/esp8266 RCSwitch libraries.

The main feature is that you can schedule events (up to 10) to turn ON/OFF your devices that repeat daily/weekly or that actuate once only within a week from setting the command.

A web interface is used to control the RF devices directly given a relative command at the main form and also scheduling the time events by giving at the same form a keyword to enter the scheduled events interface.

In the whole sketch these scheduled events are named Time Commands.

Time Commands (up to 10) execute your functions that fire the 433MHz sockets operating devices and can be set:

– Alarm Once
(once when the time next reaches the given hour, minute)
– Daily Alarm Repeat
(every day at the given hour, minute)
– Weekly Alarm Once
(once only on the next DayOfWeek, hour, minute)
– Weekly Alarm Repeat
(every week on the given DayOfWeek, hour, minute)

Here’s a video showing some basic usage of the web interface

Coding is really basic since my knowledge of C++ is minimal but hey.. it works!

For more detailed info read the README! :P https://github.com/nikant/THE433/blob/master/README.md
source code is at github: https://github.com/nikant/THE433

Example usage:

ESP8266 in the source is set as a WiFi station with a static IP

– navigate with your browser at this IP
– here you can enter either a command to activate a connected device (you must edit the source code) i.e. SWITCH 1 ON
or you can enter the provided keyword to enter the Time Commands interface i.e. ENTERTIMECOMMANDS
– at the Time Commands interface you can select a function you want to be executed at a specific time
– select the time to activate and submit
– you’ll have to restart your esp8266 and you’ll be informed about this
– after esp8266 restarts and reconnects you’ll find the saved Time Command at the bottom of the web interface (from there you can also delete it)

some screenshots follow:

esp8266: Yet another esp WiFi config to eeprom..

// Post about: esp8266 / NodeMCU.
// Info on what they are at the end of the post

Yes out there is the excellent WiFimanager for saving the config of our esp8266 and it’s great.

Just wanted to try something quick and dirty on my own (learning process)

Started looking chriscook8’s esp-arduino-apboot code and tried to rewrite the heck out of it.
The goal was to have all this in a separate file and not in my main server/project sketch. Instead have it open in another IDE tab and just make a call from the main.

  • This is not a library (and it may never become one..)
  • You must have the two files “espWiFi2eeprom.h” and “espWiFi2eeprom.ino” in the same directory with your project sketch.
  • Has been tested with NodeMCU v1.0 and Arduino IDE 1.6.5-r5 in Windows 7
  • Check “example-espWiFi2eeprom.ino” for an example of usage along with another server.
  • You can edit “espWiFi2eeprom.h” in order to change parameters.

Oh and I’m no programming guru but it works! Check it, hack it or blow it up: https://github.com/nikant/espWiFi2eeprom


info about esp8266