loading

This project will help you create a basic security system using an ESP8266 SoC and a PIR sensor with next capabilities:

  • Detect Motion
  • Ability to turn ON/OFF the system from an App on your cell phone
  • Receive an email notification in case the motion is detected and the system is turned ON
  • Monitor the status of the motion even when the system is turned OFF from your App

To complete this project you will have to create three things

  • Hardware - Basically you have to hook up the infrared sensor to the ESP8266 board and upload the Arduino code.
  • Cloud device - Create the logic that drives the decision making using the IC2Cloud platform www.ic2cloud.com
  • Mobile App - Create the mobile App using AppInventor to monitor and control your security system

    appinventor.mit.edu

This project can be easily extended to multiple sensors, more complex rules to trigger notifications and a more complex App to monitor and control.

Step 1: Get Your Materials

To complete this project you need a few things

  • A ESP8266 board. I recommend the Adafruit HUZZAH ESP8266 board. The main advantages are:
    • You get a FCC certified ESP8266 board
    • The ESPB8266 board has multiple pins exposed on the PCB
    • It has a voltage regulator on the board
    • It has buttons to trigger programming mode
  • A PIR Sensor. I used a very cheap PIR from DealExtreme These are coming in quite some variations and you can find them in many places. Please be aware that you need one that has a 3.3V output and not higher because otherwise you are going to burn the ESP8266 input using the wiring we show here.
  • Some female to female cables
  • And optional if you want to make the module stand alone a USB connector and a usb power supply....and an enclosure.

To upload the Arduino code on the ESP8266 board you need a programming cable. I recommend this one from Adafruit.

Step 2: Wiring

The wiring is very simple. You have a TOP VIEW diagram here that shows you how to do it. To be more specific you need to do three connections:

  • PIR - Vcc Pin ---> HUZZAH ESP8266 - V+ Pin (5 V pin)
  • PIR - GND Pin ---> HUZZAH ESP8266 - GND Pin
  • PIR - Out Pin ---> HUZZAH ESP8266 - #4 Pin

To be able to program it you need to connect as the programming cable too. If you use the Adafruit cable I recommend then you just plug it in with the black wire to the GND pin as shown in the picture above. For more details how to program HUZZAH board with Arduino please go to Adafruit website.

Step 3: Prepare Development Environments

To program this project you will need three development environments:

Arduino IDE for ESP8266 - You will use this to create the "firmware" for your hardware. To set-up this please follow the tutorial on the Adafruit website.

IC2Cloud Device Builder - You need this to create the monitoring code. To set-up this go to www.ic2cloud.com and register. Once you did that go to this section to create an API password.

App Inventor - You need this to create your mobile App (Android). To set-up this please go to App Inventor website and press the button Create Apps. Follow the instructions on the website. You might need a Gmail address to authenticate there.

It might sound complicated but it is fairly fast to execute all these steps.

Step 4: Program the Hardware

To program the HUZZAH board I have opted for Arduino. A lot of people are familiar with this and considering the simplicity of the code I think it can do the job quite well. I assume you followed the steps from Adafruit tutorial from the previous step.

I also assume you followed instructions to set-up you IC2Cloud account and the API access.

Once you did that please download the code I provide here (BasicSecurity.ino file from the ZIP file) and load it in the Arduino IDE. You have to modify a few things in the code to make it work

1. Modify "wifi ssid" string with your wifi SSID.

2. Modify "wifi password" string with your wifi password.

3. Modify "authentication" string with your authentication string for IC2Cloud API. Basically you have to append your user name, colon sign and password and encode the whole string using base 64 encoding. You can use this site www.base64encode.org to do that. For example if your user name is "user" and your password is "password" then you create this string:

user:password

and encode it using the tool from the link above. You should get

dXNlcjpwYXNzd29yZA=


VERY IMPORTANT!

The password is the Api Password and not your login password. The user is your email you use for login.

There is one more thing that we recommend to change (but let's not do it until you understand the inner workings of the entire project) is the device Id.

Last thing is to compile and upload the code on your ESP board. I assume you are familiar with Arduino IDE and once you are properly set up for the ESP board this should be easy.

Step 5: Verify Communication With the Cloud

Once you completed the previous step it is recommended that you verify the communication with the cloud.

If you are familiar with the debug in Arduino please use serial communication to check if everything is OK. You can also go to the Signal Manager on the IC2Cloud website to test if the MOTION signal is sent to the cloud.

The picture above shows you how to do it.

Please be aware that the signal is sent when motion is detected (MOTION,YES) and it is not reset to (MOTION, NO) because that part will be in the cloud device code and on the mobile app.

To test it properly you have to manually set it to NO in the signal manager.

Make sure you get the signal when motion is detected. Reset MOTION signal manually to NO and try again a few times. If this is working properly then your hardware is up and running..

Step 6: Create the Cloud Device

Using the IC2Cloud Device Builder import the BasicSecurity.vcd file on the online IDE. You should see the picture above. The steps you need to do are:

  • Set your own email address as destination.
  • Save the Device with a Name (Le's say "Basic Security").

The logic is fairly simple. The cloud device will read the MOTION signal and ALARM signal. The last signal is set by the mobile application you will create in the next step to activate/deactivate the signal.

Once that is done you need to start this cloud device.

Go to the Device Manager on the IC2Cloud site and press the button start next to it. You should get a confirmation the device is started and it runs.

Step 7: Create the Mobile App

Using App Inventor from MIT you will create the mobile application. Once you are set-up with App Inventor you can go and import the BasicSecurity.aia file. Once you open the project you should see the user interface designer. Switch to blocks section and you will see the picture above.

The only thing you need to change is your authentication string you have created in the previous steps.

VERY IMPORTANT!
The password is the Api Password and not your login password. The user is your email you use for login.

Once that is done you can download the App on your phone and you have everything ready. Follow the instructions on the App Inventor site how to execute the steps.

Step 8: Using the Security System

Open the mobile application you have created and you are gong to get a screen like the one above.

Here you can see your motion status from the sensor. You can reset it by pressing the OFF button.

Pressing ON button will activate the security system. Whenever motion is detected the system will send you an email.

To de-activate the alarm press the OFF button.

This concludes the project. You have a security system IoT style ;-)

You can improve it. Here you have a few ideas:

  • Add multiple sensors.
  • Create different modes: day, night, etc.
  • You can create other sensors to integrate in this system.
  • Detect lost connection with sensor (if you have not received an signal in the last 5 minutes from the sensor send a warning email)
  • Add a Bluetooth beacon that detects the presence of you phones in the house and none are in the range activate automatically the system
  • ...and whatever you come up with ;-)

Anyway, if you managed to get to this point then you have the basic skeleton of a security system that will notify you of potential intruders.

Please keep in mind this is experimental and you need to make your own judgements how you use this project.

Good luck!

<p>Hello!</p><p>What would be the pins for WEMOS ESP8266 D1 mini ?</p><p>Thank you!</p>
<p>Great tutorial, I didn't have any programming cable so I had to gigure out how to use the Arduino UNO as a substitute. I had the same problem as the user &quot;RFcontrollerSwith&quot; below and solved it by keeping Basic followed by my authentication. I thought I had to replace all the characters in that line. Now I'll try to learn the App Builder to make something more advanced! Thank you!</p>
<p>Changed the api password and that seems to have fixed it. Although the Signal Manager with IC2 doesn't seem to give live data now. It's the app that I want live data from rather than the Signal Manager and the app is fine now.</p>
<p>Nice instructable. I am getting emails to tell me when the 'alarm' is triggered but the app doesn't appear to working correctly. When I start up the app it shows N/A against ALARM and MOTION for about a second and then they both change to &quot;Arial&quot; rather than ON OFF YES NO. I can see N/A in your app builder file and I have tried changing fonts etc but still only get 'Arial'. Any ideas what the fix is?</p>

About This Instructable

12,226views

80favorites

License:

More by anistor:Illuminance Monitor with ESP8266 - IoT Temperature Monitor with ESP8266 - IoT Basic Security with ESP8266 - IoT 
Add instructable to: