10 May 2015

Arduino sending mobile Push notifications about front door

I wanted to be notified about people entering my house. This could be my neighbor to pick up the mail while being on a holiday, our cleaning lady when being at work or my spouse so I would know it was time to go home ;)

Why monitor entrance to your house?

My two main reasons for this project were:
  1. Security and control, when somebody would enter unexpectedly, I could ask somebody to go and take a look.
  2. Because I can. >:)

Two Arduino’s

I really like all the posibilties with Arduino’s. For this project I used two Arduino’s.

Monitoring the door

One to be monitoring my door with a reed contact sensor.

Reed contact sensor



When the door is opened, the input pin goes HIGH, so my Arduino 'knows' the door is open. When closing the input goes LOW again. Let’s call this one the “Front-door Arduino”.

Connection to the internet

Because I don’t have a wired internet connection at my door, I used a second (Ethernet-)Arduino that was connected to my router. Let’s call this one the “Internet Arduino”.
The Internet Arduino sends API calls to Pushover. Pushover makes it easy to send push notifications to your Android phone or iPhone.

RF-Link for wireless data communication

The front-door Arduino communicates with the Internet Arduino about the door status.
For this connection I used two DFRobot APC220 Radio Communication Modules. They make a perfectly stable serial connection between both ends.



APC220 Radio Communication Modules

Because of this separated setup, it also enhances security. When the ’intruder’ would tamper with the Front-door Arduino, the (hidden) Internet Arduino would notice and send me a push notification to tell me that there is something wrong with the setup.

Schematic

My Setup looks like this:

Pushover

As you can see, the Internet Arduino sends a message to Pushover. You can make a free account there that allows you to send and receive push notifications on your mobile phone.

In your Pushover account, you’ll find a userkey. Also register an ‘Application’, this will be your Arduino sending stuff. Pushover will give you an Application API token/key as well. You need those two values (userkey and API token).

Video

This works like a charm:

Source code

Do you want to build your own setup? Please let me help you with my source code:


Disadvantages

Right now, my Front door Arduino is consuming some power and I need a wire to an outlet to power my Arduino. There must be a smarter way to handle the ‘detecting’-part of this solution. I am working on this now. :)

1 comment:

  1. Halo Rogier, leuk project!

    Maar misschien kunt jij mij helpen? Ik heb een code die het zelfde doet. Maar met een esp8266 via ifttt naar pushover. Alles werkt! Maar ik wil graag dat de notificatie, direct via pushover gaat. En ik ben geen guru hier in:(

    Hier is de code:

    #include "Pushover.h"
    #include
    #include

    #define REED_SWITCH 5 //D1

    int status = WL_IDLE_STATUS; //not required.

    const char* ssid = "************************";
    const char* password = "************************";
    int doorClosed = 1;

    void setup() {
    pinMode(REED_SWITCH, INPUT_PULLUP);

    Serial.begin(115200);

    setupWifi();

    //get_http();
    }

    void setupWifi()
    {
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    WiFi.mode(WIFI_STA);
    status = WiFi.begin(ssid, password);

    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);

    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
    }
    Serial.println("Connected to wifi");
    }

    void loop() {
    if (WiFi.status() != WL_CONNECTED)
    {
    setupWifi();
    }
    // put your main code here, to run repeatedly:
    if ((digitalRead(REED_SWITCH) == HIGH) && (doorClosed == 1))
    {
    Serial.println("DOOR OPEN!!");
    while (get_http(String("DOOR_OPEN_")) != 0);
    doorClosed = 0;
    }
    else if ((digitalRead(REED_SWITCH) == LOW) && (doorClosed == 0))
    {
    Serial.println("DOOR CLOSED!!");
    while (get_http(String("DOOR_CLOSED_")) != 0);
    doorClosed = 1;
    }
    delay(10);

    }

    int get_http(String state)
    {

    HTTPClient http;
    int ret = 0;
    Serial.print("[HTTP] begin...\n");
    // configure ifttt server and url should be HTTP only..not https!!! (http://)
    http.begin("http://maker.ifttt.com/trigger/Open!/with/key/************************"); //HTTP
    //If you have enabled value1 from iftt settings then uncomment below line to send value and comment out above line
    //http.begin("http://maker.ifttt.com/trigger/door/with/key/your_key_from_Iftt/?value1="+state); //HTTP

    Serial.print("[HTTP] GET...\n");
    // start connection and send HTTP header
    int httpCode = http.GET();
    // httpCode will be negative on error
    if(httpCode > 0) {
    // HTTP header has been send and Server response header has been handled
    Serial.printf("[HTTP] GET code: %d\n", httpCode);

    if(httpCode == HTTP_CODE_OK) {
    String payload = http.getString();
    Serial.println(payload);
    }
    } else {
    ret = -1;
    Serial.printf("[HTTP] GET failed, error: %s\n", http.errorToString(httpCode).c_str());
    delay(500); // wait for half sec before retry again
    }

    http.end();
    return ret;
    }

    ReplyDelete