Arduino, Monitoring Door-Opening Via Gmail

1,485

24

6

Introduction: Arduino, Monitoring Door-Opening Via Gmail

In this tutorial, I am going to show you how to detect the door-opening event and send a notification via Gmail using Arduino Uno.

If you are a beginner, you can learn about wifi and sensor in Arduino - WiFi and Arduino - Door Sensor tutorials.

Let's get started!

Detecting Door-Opening Event
Magnetic sensor I used includes two parts: sensor and magnet. When two parts are in proximity, the output pin of the sensor is HIGH, otherwise the output pin is LOW. Taking advantage of this feature, I installed one part of the sensor on the door leaf and the other on the door frame. By checking state of the output pin, we can detect when door is opened and then make an alert or send a notification.

Handling Event

When the door-opening event occurs, a notification is sent via Gmail.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Things We Need

Step 2: Assembly

1. Stack PHPoC Shield on Arduino.

2. Connect LAN cable to the shield for Ethernet.

3. Pin wiring between Arduino and Sensor.

----5v--------red pin.

----A0-------black pin.

Step 3: Install This Set on the Door

1. Attach the sensor part, Arduino set (including PHPoC shield) to the door frame

2. Attach the magnet part on the door leaf.

3. Power Arduino

4. Connect to Internet via LAN cable or USB Wifi Dongle.

Step 4: Download and Install Library on Arduino

Install PHPoC and ezButton library

Step 5: Arduino Code

#include <Phpoc.h>
#include <ezButton.h>

PhpocEmail email;
ezButton button(A0);  // create Button object that attach to pin A0;

void setup() {
  Serial.begin(9600);
  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP);
  //Phpoc.beginIP6(); uncomment this line if you are going to use IPv6
  button.setDebounceTime(100); // set debounce time to 100 milliseconds
}

void loop() {
  button.loop(); // MUST call the loop() function first
  if(button.isPressed()) {    // if door is opened...
    email.setOutgoingServer("smtp.gmail.com", 587);
    email.setOutgoingLogin("Google ID", "Google Password");
 
    email.setFrom("Gmail address ", "Sender Name");
    email.setTo("Receiver email address", "Receiver Name");
    
    email.setSubject("Door is opened. [#905]");  // Mail Subject
    
    // Mail Contents
    email.beginMessage();
    email.println("#905");
    email.println("");
    email.println("Door is opened.");
    email.endMessage();                
 
    if (email.send() > 0)  // Send Email
      Serial.println("Your Mail has been sent successfully");
    else
      Serial.println("Your Mail is not sent");
  } else if (button.isReleased()) { // if door is closed...
        // Write codes in the same way
  }
}

Be the First to Share

    Recommendations

    • LED Strip Speed Challenge

      LED Strip Speed Challenge
    • Sculpting Challenge

      Sculpting Challenge
    • Tiny Speed Challenge

      Tiny Speed Challenge

    6 Discussions

    0
    virna310
    virna310

    Question 1 year ago on Step 5

    Hi this is a very interesting project, iam planning to create this for my year 12 I.T assignment, would i need to use any breadboard for this and since iam a new beginner do you think that i would be able to make this? Thank you so much :)

    0
    phpoc_man
    phpoc_man

    Answer 1 year ago

    Hello Virna,

    This project is very simple. No need breadboard. Because it requires only two wires to connect to arduino. Therefore, we can connect directly to Arduino pin.

    0
    feftwlol
    feftwlol

    Question 1 year ago

    Great Project! Is there an an advantage to using the PHPoc shield for network access vs the arduino ethernet shield? I was going to try this with the arduino shield but if you think that's a bad idea I'd like to know

    0
    phpoc_man
    phpoc_man

    Answer 1 year ago

    Hello feftwlol,

    Theo outstanding features of PHPoC Shield are:

    - It has an embedded webserver, offering the controlling and monitoring solution via web. The embedded web app can run on multiple platform.

    - It has some built-in web applications, which help users who don't have knowledge of web programming can use it.

    -It supports WebSocket that allow web app on web browser can exchange data with Arduino in real-time without reloading webpage

    - It supports sending email via SMTP and ESMTP protocol. Most of other shields do NOT supports ESMTP. That is reason why they can NOT send email via Gmail.

    - Support many security features. You event use it with WiFi enterprise

    - It can do anything other shield can do.

    you can see more PHPoC Shield project here.

    https://www.hackster.io/phpoc/products/phpoc-wifi-...

    https://www.hackster.io/phpoc/products/phpoc-shiel...

    Its own library also contains many useful examples

    0
    Swansong
    Swansong

    3 years ago

    That's a neat idea :)

    0
    phpoc_man
    phpoc_man

    Reply 3 years ago

    Thank you!