Project tutorial
MotionSense

MotionSense © MIT

Motion activated Pushbullet notification from your Arduino to your Smart Gadgets

  • 7,953 views
  • 6 comments
  • 7 respects

Components and supplies

Arduino Mega
×1
Esp01
Espressif ESP8266 ESP-01
×1
HC-SR501 PIR sensor
×1
1000uF capacitor
×1
Resistors and Jumper wires
×1

Necessary tools and machines

Wire cutter

Apps and online services

About this project

MotionSense

Introduction

In this tutorial, I will discuss how to create a system that notify any unauthorized activity or intrusion. I had used Arduino and PIR for activity detection and ESP8266 for WiFi connectivity. My Xperia Z1 is used for getting notification. I used populer notification app Pushbullet for getting notification and the Pushbullet APIs for sending notification from Arduino.


Prerequisite Knowledge

  • Knowledge in Arduino and basic hardwares [ visit : www.arduino.cc]
  • Idea about AT commands [ read : http://www.codeproject.com/Articles/85636/Introduction-to-AT-commands-and-its-uses ]
  • PIR, how it works [ about : https://en.wikipedia.org/wiki/Passive_infrared_sensor ]


'Things' used

Arduino Mega 2560

ESP8266 serial WiFi ESP-01 variant

HC-SR501 PIR sensor

1000 µF capacitor, different resistors [ capacitor for WiFi power supply, resistor for voltage regulation ]

Single thread 0.5mm wires [ connector lead ]

Female-female jumper wires [ connectors ]

Xperia Z1 [ for Pushbullet app, any smartphone will do ]

My Laptop [ coding in arduino ]

Arduino IDE [v1.6.4]


What to DO

Environment set up : If you don't have arduino installed, install it from arduino website.

Hide Copy Code

Setting up PIR :

I assume you need maximum sensitivity with minimum alert cycle to get better detection rate. Hence set PIR sensor pots like that :

Now open the white sphere of the PIR sensor and you will see pin description : GND | OUT | VCC

Connect female jumpers with GND VCC and OUT.

Now connect other end of jumper pins (connected to PIR) to Arduino :

PIR GND -> Arduino GND

PIR VCC - > Arduino 5V

PIR OUT - > DIGITAL pin 2 [ you can choose pin according to your choice and change in arduino code also ]

To test your PIR you can use this code in Arduino Playground

So your PIR sensor is READY to work

Hide Copy Code

Enabling Arduino to connect to internet via WiFi :

I used ESP8266 (variant ESP-01 ) serial WiFi module for my project which is pretty cheap. There are other variants available apart from ESP-01. There are different firmwares too available. I used the default one, AT firmware. Check this two images for connection reference

No connect ESP8266 with Arduino with jumper wire :

ESP8266 GND - > Arduino GND

ESP8266 UXTX (transmit pin) -> Arduino RX2 (arduino mega receiver pin, ie. Serial2 in code)

ESP8266 CH_PD (make HIGH) -> Arduino 5V (add one voltage regulator 0f 3.3 as ESP 8266 can tolerate 3.3v. I have used a resistor as I didn't have voltage regulator. But voltage regulator is preferred)

leave RST, GPIO2 and GPIO0 not connected

ESP8266 URXD (receiver pin) - > Arduino TX2 (arduino receiver pin ie. Serial2 in code)

ESP8266 VCC - > 3.3v of Arduino

ESP8266 has power issue at the time of data transmission. It draws power from arduino so much that arduino may restart if Arduino is powered via PC USB. Even with 5v power supply through power plug may not suffice. Hence it is always recommended to use external power supply for ESP8266. However in my experiment I used a quick & cheap solution for this. I used one 1000µF electrolyte capacitor to supply enough power to ESP8266.

longer pin - > ESP8266 VCC connected to 3.3v

shorter pin - > ESP8266 GND connected to arduino GND

So your ESP8266 WiFi module is READY to work

Hide Copy Code

Pushbullet Notifier :

Pushbullet let you seemlessly notify your different devices through push notifications. We are going to use it's API for push notification of our PIR sensor. READ MORE about Pushbullet

Let's start.

Go to PushBullet

Register yourself, download chrome app and Smartphone app.

Log on to Pushbullet in your devices.

Now see how it works sending some push messages to your devices using app or chrome extension installed in your PC.

Go to API section

NOTE : Here all the API link and URLs are provided for https connection and Arduino can not use https as it is not that powerful to handle that. Hence we will use HTTP version of those APIs which is not mentioned here in pushbullet docs but I got this reference from github.

In pushbullet docs for pushing they had mentioned URL which is HTTPS, so we will use HTTP URL and port provided in that github project. Also we will add /pushbullet before and REST path they had mentioned.

Example :

for notification push to all devices , according to pushbullet doc, REST path is : /v2/pushes

but we will use : /pushbullet/v2/pushes

base URL : 173.17.168.19

port : 8181

Now check different API and read descriptions to know about them. You can use them later on for your enhanced version of this tutorial.

You need your authentication key to push from arduino. So go to your Account

Look for Access Token, copy & save this to your PC in secure place.

So Pushbullet is now READY to sending and receiving Push notification.


It's time to code now

Open this GitHub Project

Go to Experiments folder. There you will find MotionSense.ino, your code which will push notification to your Smart Devices.

Copy this code to arduino IDE and connect your arduino ( already set up with WiFi and PIR sensor ).

Now change these parameters :

Hide Copy Code

#define SSID "YOURSSID" /* replace YOURSSID with your WiFi access point name */
#define PASS "YOURPASSWORD" /* replace YOUR PASSWORD with your WiFi access point password */

You may want to change PIR OUT pin to your desired pin

Hide Copy Code

#define PIRPIN 2 /* change to your desired digital pin of your arduino */
#define AUTH_TOKEN "YOUR_TOKEN_FROM_YOUR_ACCOUNT";
/* replace  YOUR_TOKEN_FROM_YOUR_ACCOUNT with your Access Token*/

Also use your access token as mentioned in above snippet.

Now compile and run.

It will take time for sensor calibration, WiFi module initialization and for connecting to your access point.

You can see these things in your Serial monitor.

After everything will done, it will start looping through main loop and you will see

"Everything fine | No intrusion "

in your serial monitor continuously.

Whenever you go go infront of your PIR sensor, it will detect movement and Push notification to your devices.


Understanding Code in brief

#defines are set of predefined parameters you need to change accordingly

In set up you can see initializing arduino Serial(). Serial2 is for WiFi serial access.

Understanding functions :

Hide Copy Code

sensor_calibration (); 
/* It calibrates sensor for proper output. We need to power down PIRPIN before that */

Hide Copy Code

check_WiFi_radio (); /* Checks whether WiFi module is OK or not */

Hide Copy Code

reset_wifi (); /* resets WiFi module to clear any problem */

Hide Copy Code

set_wifi_mode (); /* Set WiFi module as client for connecting to Access Point */

After setting WiFi mode you need to reset WiFi to set it

Hide Copy Code

check_wifi_stat (); /* Checks whether your WiFi module is connected to AP or not */

Hide Copy Code

connect_ssid (); /* if not connected, then will connect with your connection parameter */

Upto this, your WiFi module initialized and connected, Now you need to check PIR reading whether it sensed motion or not. It will be under main loop.

Hide Copy Code

pirRead ();
/* reads PIR value, either 0 or 1. If 1, then Motion Sensed, if 0, then nothing is there */

If something detected, then first you need to connect to Pushbullet server

Hide Copy Code

server_connect (); /* connecting to server */

Now Push Notification

Hide Copy Code

post (); /* pushing notification to all devices */

disconnect

Hide Copy Code

server_disconnect (); /* close server connectioon */

and loop through

Code

MotionSense code
Read repository readme for code explanation

Schematics

esp8266.jpeg
Esp8266

Comments

Similar projects you might like

IoT arduino ESP Garage Door opener (UD)

Project in progress by David Smerkous

  • 13,624 views
  • 6 comments
  • 20 respects

IoT Using ESP8266-01 and Arduino

Project tutorial by Ahmed Ibrahim Ahmed

  • 7,759 views
  • 11 comments
  • 44 respects

DIY Air Humidifier with Backlight Controlled by Alexa

Project tutorial by Andrii Romanenko

  • 2,267 views
  • 0 comments
  • 8 respects

How To Use TheAmplituhedron.com To Improve IoT Projects

Project tutorial by Kutluhan Aktar

  • 1,864 views
  • 0 comments
  • 9 respects

WiFi IR Blaster

Project tutorial by BuddyC

  • 99,654 views
  • 44 comments
  • 103 respects

OH HAI! on Windows 10 IoT Core

Project in progress by BuddyC

  • 14,210 views
  • 3 comments
  • 50 respects
Add projectSign up / Login