IoT WiFi DIY motion detector with e-mail notification using PIR sensor and ESP8266

In this project I am using the ESP8266 WiFi module and PIR sensor motion detector to get e-mail alerts if someone enters the room while I am away. I am using GadgetKeeper Cloud Platform to bring e-mail notifications with PIR Sensor. I have choose GadgetKeeper Cloud Platform because it’s FREE and easy to use. The whole project costed me around $7 and was pretty easy to build.

Step 1: Parts

  • 1× esp8266-07 – Ebay;
  • 1× PIR Sensor – Ebay;
  • 1x Bread Board Power Supply – Ebay;
  • 1x 12V AC-DC Power Adaptor – Ebay;
  • 2x 400pin Breadboard – Ebay;
  • Wires.

I used my 12 V DC adaptor that was laying around, but any 5-12 DC adaptor will work.

Step 2: Prepare the hardware

Picture of Prepare the hardware20151007_220533.jpg20151007_220538.jpg20151007_220555_001.jpg20151007_220558.jpg20151007_220610.jpg

  • ESP8266 Wiring;
    • Reset     -> via push button to gnd;
    • GPIO12 -> PIR sensor data pin;
    • VCC       -> 3V3;
    • TXD       -> CP2102 TXD Pin;
    •  RXD      -> CP2102 RXD Pin;
    •  GPIO0  -> GND;
    •  GND     -> GND;
  • CP2102 Wiring;
    • TDX -> ESP8266 TXD Pin;
    • RXD -> ESP8266 RXD Pin;
    • GND -> GND;
  • PIR sensor;
    • VCC -> 5V;
    • GND -> GND;
    • OUT -> ESP8266 GPIO12 Pin.

NOTE: to upload code to ESP8266 first connect GPIO0 pin to ground, reset the ESP8266 WiFi module (I have done it via push button connected to ESP8266 reset pin and GND) then upload code. After uploading code GPIO0 can be disconnected again.

Step 3: Prepare Arduino IDE

Download here Arduino IDE from Arduino.cc (1.6.4 or greater) – don’t use 1.6.2! You can use your existing IDE if you have already installed it. You can also try downloading, here, the ready-to-go package from the ESP8266-Arduino project, if the proxy is giving you problems.

Picture of Prepare Arduino IDE

Enter:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

into Additional Board Manager URLs field in the Arduino v1.6.4+ preferences. Next, use the Board manager to install the ESP8266 package.

Picture of Prepare Arduino IDE

Step 4: Additional Arduino libraries

The required libraries can be downloaded from following link:

All other required libraries are available as standard libraries with the IDE. Installing Additional Arduino Libraries guidelines can be found on official Arduino site.

Step 5: Configure GadgetKeeper

After successfully creating account on GadgetKeeper, go to console and create the “Alarm” thing first.

Picture of Configure GadgetKeeper

After successfully creating Alarm thing write down your Thing ID. If you need detailed “point and click” UI instructions how to create thing see “Create, Read, and Write Property” on GadgetKeeper Documentation. Create Motion detected event for Alarm thing in GadgetKeeper Console.

GadgetKeeper Console - Mozilla Firefox_051.png

  1. In the “Thing: Alarm” tab, open “Events”
  2. Click “New” to open “Create Event” dialog
  3. Set name to “Motion detected”
  4. Select “boolean” as the data type for this event
  5. Save event

If you need detailed “point and click” UI instructions how to create even see “Create Event And Trigger” on GadgetKeeper Documentation. Create Mail notification trigger for Alarm thing in GadgetKeeper Console.

GadgetKeeper Console - Mozilla Firefox_059.png

  1. Open “Triggers” in the “Thing: Alarm” tab
  2. Click “New” to open “Create Script Trigger” dialog
  3. Set name to “Mail notification”
  4. Select “Motion detected” as the event used for the trigger
  5. Save trigger by clicking “Save”

if you need detailed “point and click” UI instructions how to create even see “Create Event And Trigger” on GadgetKeeper Documentation. Add script to Mail notification trigger for Alarm thing in GadgetKeeper Console.

Picture of Configure GadgetKeeper

  1. Open “Triggers” again in the “Thing: Alarm” tab
  2. Select “Mail notification”
  3. Click “Edit Script” button to open “Edit Script Trigger” dialog
  4. Insert the following script in the text area (email name may be edited):

function onEvent(event){
if(event.value == true) smtp.send(“user@gmail.com”, “Motion detected!”);

}

5. Save the trigger script by clicking “Save”

if you need detailed “point and click” UI instructions how to create even see “Create Event And Trigger” on GadgetKeeper Documentation.

Step 6: Arduino sketch

This is the arduino sketch for this cheap homemade IoT device.

Information about uploading Arduino Sketch can be found here.

About the Author

Elvir Becic. Twitter: @BecicElvir. Electrical engineer, hobbyist, interested in IoT, Arduino, Raspberry Pi, Home Automation.

One thought on “IoT WiFi DIY motion detector with e-mail notification using PIR sensor and ESP8266

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s