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

Forecast Jar

There are a lot of IoT projects out there dealing with weather / weather conditions etc. I’ve been tinkering with some as it’s a great way to learn things around microcontroller boards like Arduino.

After playing around with some designs I wanted something simple for my room to check tomorrow’s weather forecast at a glance.

So this is the Forecast Jar.

Design is simple component side. An esp8266, two RGB common anode leds and a DHT22 sensor for local weather conditions.

The code (is a mess but “Hey! It compiles!”) uses Weather Underground API in its free version which offers enough daily requests for this project.

Of course Forecast Jar has a web interface (esp8266 ;)) in which you can check local conditions reported from DHT22 sensor and, more importantly, you can change the location of the Forecast Jar with latitude and longitude so it can request the correct conditions from Weather Underground.

Also in the web interface there is the color legend for the forecast conditions

The Forecast Jar (in code) is also connected to IFTTT Maker if needed and reports it’s DHT22 data to a ThingSpeak channel so we can have pretty graphs of our room temperature and humidity :)

The sewage watch

aka “dirt PUMP” watch :p

Oh well someone has to watch over our sewage pump. Which has already a panel that control when to start / stop the pump or when to turn on heat protection when there’s no “water” left.

The problem was that this control panel is two floors down and if we wanted to check its condition (i.e. after a power failure or if the pump has stopped for heat protection) we should make regular passes from the basement.

The good thing about this control panel is that it has its own LEDs showing the status of the pump (Power Supply, Motor On, Motor Protection, Automatic (on/off), Level Alarm and No Water Alarm).

Enter esp8266 / NodeMCU.

With the use of six photoresistors (CdS, LDR) we can read the status of each LED of the control panel and output its status on a web page. Yippee..

The schematics on how to connect LDRs to an esp8266 or a NodeMCU are all over the web if you look. For three LDRs for example is the following:

In the code I’m reading the digital output of each LDR as 0 or 1.

Putting the six LDRs in the correct positions was easy on a 9x15cm prototyping PCB (luckily 9cm was the height of the opening of the control panel).

Reversing the PCB and placing it over the control panel with a breadboard to hold the NodeMCU for testing:

there was some duct tape involved.. (Duct tape is for everything right?)

Aaand we have our output readings in a static IP in our network (where green color is good):

In the code of the NodeMCU (with Arduino IDE) there is also a part that connects with IFTTT Maker channel to notify me for important events.


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