Project tutorial
Arduino, Monitoring Door-Opening via Gmail

Arduino, Monitoring Door-Opening via Gmail © GPL3+

When the door is opened, Arduino sends a notification via Gmail. Magnetic Sensor is used to detect the door open. It can be used with IPv6.

  • 27,065 views
  • 38 comments
  • 86 respects

Components and supplies

About this project

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. I made this tutorial for beginners! It is really easy!

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

In this project, when an event occurs, a notification is sent via Gmail.

Code

Source CodeArduino
#include "SPI.h"
#include "Phpoc.h"
 
PhpocEmail email;
 
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
  
  pinMode(A0, INPUT);
}
 
int previous_status = 1;
 
 
void loop() {
  int current_status = digitalRead(A0);
  int returnValue;
  
  if (previous_status == 1 && current_status == 0) {    // 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 (previous_status == 0 && current_status == 1) { // if door is closed...
 
        // Write codes in the same way
  
  }
 
  previous_status = current_status;
  delay(1500);
 
}
PHPoC library for Arduino
This library communicates with PHPoC Shield to connect to the Internet. It's also contains Gmail library. How to install library: http://www.phpoc.com/support/manual/phpoc_shield_for_arduino/

Schematics

Things we need
Components p4vl4dkluu
Assembly
1. Stack PHPoC Shield on Arduino
2. Connect LAN cable or USB wifi Dongle to the shield for Ethernet
3. Pin wiring between Arduino and Sensor.
----5V--------red pin
----A0-------black pin
Assembly qgnyr78p8r

Comments

Similar projects you might like

Security Access Using RFID Reader

by Aritro Mukherjee

  • 260,262 views
  • 42 comments
  • 281 respects

Water Quality Monitoring System

Project tutorial by Hao Jie Chan

  • 29,126 views
  • 41 comments
  • 61 respects

Gmail & Arduino UNO & IPv6

by phpoc_man

  • 2,398 views
  • 0 comments
  • 14 respects

Arduino - Detect Someone Taking Your Stuff and send Gmail

Project showcase by IoT_lover

  • 7,942 views
  • 22 comments
  • 24 respects

Monitoring the Fill Height of Paper Shredder

Project showcase by phpoc_man

  • 860 views
  • 4 comments
  • 17 respects

Motion Following Motorized Camera Base

Project tutorial by Lindsay Fox

  • 113,764 views
  • 68 comments
  • 287 respects
Add projectSign up / Login