loading

In this tutorial we will see how to make a home security system which can post alerts to TWITTER. We will use the ESP866 Wi-Fi chip to communicate to the internet. For the purpose of this tutorial i have included two sensors that are the PIR motion sensor as well as a GAS sensor for LPG gas leak detection. So lets get started.

Step 1: Parts Required

  • HARDWARE-
  1. Atmega328 microcontroller. You may use any arduino based microcontroller.
  2. ESP8266. Any version of this chip will work fine. You may also use the nodemcu. I have made my own board so i will not be using the nodemcu.
  3. MQ-6 Gas Sensor
  4. PIR sensor.
  5. Power supply.
  6. Passive components(capacitors and resistors)
  7. Switches
  8. Breadboard and Jumper cables.

  • SOFTWARE-
  1. THINGSPEAK account.
  2. ARDUINO IDE.

Step 2: THE WORKING AND SCHEMATICS

The main goal behind this project is to collect the data from an array of sensors and to send it over to TWITTER in particular. Hence to acquire the data from the sensors the ATmega microcontroller was used. Next part of the project is to send the acquired data over to the THINGSPEAK account(which u should have. Its a great tool for IOT based projects.) and for doing that we use an ESP8266. Before the ESP8266 days we had the the Ethernet shield which was rather expensive. The ESP8266 is really cheap(usually below $3) and gets the work done. It is just a little bit tricky to set it up and get things going.

The Schematic -

ARDUINO -

PIN 13 is connected to the OUTPUT of the PIR sensor.

PIN A0 is connected to the ANALOG output of the gas sensor.

PIN 7 is connected to the ESP8266 TX(use of a 5v-3.3v level shifter is advised)

PIN 8 is connected to the ESP8266 RX(use of a 5v- 3.3v level shifter is advised)

CAUTION- ESP8266 is not 5v tolerant. if you give 5v to any of the pins the ESP8266 might stop working.

The rest of the connections are VCC and GND.

I have made Two boards one for an an ATmega328p based Arduino board and another one for the ESP8266 breakout board.

Step 3: SOFTWARE PART

1. ARDUINO -

There is not much to it when it comes to the Arduino code. You just have to monitor the sensors and if they trigger you have to communicate with the ESP8266 telling it what happened and what to do.

The monitoring part is simple. But for communicating with the ESP8266 we need the UART interface. ATmega328p only has one hardware UART which is connected to the PC and is used for debugging (you can use this to communicate with ESP). So we use the SOFTWARE SERIAL library which can simulate the UART interface on any pins we wish to use. I have used pin 7 and 8 as RX and TX which are connected to the TX and RX of the ESP8266.

2. ESP8266 -

Before you do anything with the ESP8266 make sure that you have updated it with the nodemcu firmware. This will allow us to use the ESP8266 with the ARDUINO IDE. You will also have to add ESP8266 support to the ARDUINO IDE. The how-to is easily available on the internet.

After you have done the above things make sure you have an account on the Thingspeak website.

Once you log in to the account go to the apps menu and scroll down till you find 'THING TWEET'. Here you will be asked by the twitter to give permission to the THINGSPEAK service to post tweets on your behalf. Once you give the permission you will be able given an API KEY which is used by our application code to access our twitter account.

The other thing that is required is to post time with the tweet. Instead of using a RTC module i have used the 'THING HTTP' app to acquire time from a website and return it to my ESP8266. What it does is it essentially read a webpage and return back the String from the webpage which we have instructed it to do so.

Let's see how to do it -

LOG in to your Thingspeak account. Go To apps > THING HTTP. Create a new new THING HTTP app.

NEXT go to the website from where you want to acquire the current time.

When you see the time right click on it and select INSPECT.

It will take you to the source code of the webpage. Right click on the line which has the code to display the time and copy its Xpath.

Now go back to you THING HTTP page.

Enter the website URL in the URL tab. Select the http version 1.0.

Scroll down to the bottom where it says Parse String and paste the Xpath there. Save it.

You will be given the API key. Go to a new tab and open this url -

https: //api.thingspeak.com/apps/thinghttp/send_request?api_key='your api key'

Here you will see the time. if you don't see the time please make sure you have selected the correct Xpath for the acquisition of the time from the website.

We will bee needing these two API keys in our code.

UPLOAD the code to the esp8266 and Arduino board. Make the connections and see the results.

I HAVE ATTACHED ALL THE SCREENSHOTS ABOVE. PLEASE MAKE SURE YOU CLICK ON THEM AND SCROLL THROUGH THEM.


Step 4: RESULTS

The final board and the result on the twitter.

<p>Is the arduino really required. Why can't it be on the ESP itself. </p>
<p>ESP8266 is a great chip. It's only quirk is that it has less available pins.</p>
<p>About the using a op-amp with the gas sensor, that was available in the sensor module i used. We can set a reference voltage point on the module itself. It triggers a 5v output if the analog value goes above the reference point. But then again i have other ideas for this project. Like interfacing a keyboard for passcode etc. So i plan on using a Arduino mega instead of the atmega328. </p>
<p>Nice project, but you can connect all these sensors (and more) directly to esp8266, atmega unnecessary there.</p>
<p>Yeah sure. This can be done with a standalone esp8266 but the esp has just one 1v analog input. So with future expansion in mind in thought it was better to add external microcontroller.</p>
<p>I guess, building the Gas sensor with a small opamp with adjustable logic output and interfacing it with the ESP8266 port pin would have been a better idea. In which case you could have simply eliminated the Arduino and made the project simple and attractive. Anyway, just my thought and idea.</p>

About This Instructable

2,074views

62favorites

License:

More by sbx20:Home Security System Using ESP8266, TWITTER and Thingspeak. Arduino + MFRC522 RFID READER 
Add instructable to: