Things used in this project

Schematics

Wiring
1. Stack PHPoC Shield on Arduino
2. Connect Force sensor and relay to Arduino as bellow image
Arduino wiring jutlmecazu
Real Wiring
Arduino wiring real 9dxjinknrg

Code

Arduino CodeArduino
#include "SPI.h"
#include "Phpoc.h"

PhpocEmail email;
PhpocDateTime datetime;

const int THRESHOLD = 50;
boolean objPresent = false;
long adcValue = 0;

boolean sendGmail();

void setup() {
    Serial.begin(9600);
    while(!Serial)
    ;
    pinMode(A0, INPUT); // to read value from sensor
	pinMode(5, OUTPUT); // to control relay
    
    Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP);
    datetime.date("Y-M-d H:i:s");
    
}

void loop() {
    // read 30 time and get average value to eliminate noises
    adcValue = 0;
    
    for(int i = 0; i < 30; i++)
    {
        adcValue += analogRead(A0);
        delay(10);
    }
    
    adcValue /= 30;
    
    if(adcValue < THRESHOLD)
    {
        
        if(objPresent)
        {
            //Alert
             digitalWrite(5, HIGH);
            // send notification
            while(!sendGmail())
               ;
            
            objPresent = false;
        }
    }
    else
    {
        objPresent = true;
        digitalWrite(5, LOW);
    }
}

boolean sendGmail(){
    // setup outgoing relay server - gmail.com
    email.setOutgoingServer("smtp.gmail.com", 587);
    email.setOutgoingLogin("your_account", "your_password");
    
    // setup From/To/Subject
    email.setFrom("your_account@gmail.com", "Arduino");
    email.setTo("receiver_account@gmail.com", "Boss");
    
    email.setSubject("Alert: Your treasure is being taken away");
    
    // write email message
    email.beginMessage();
    email.println("Location: Planet Earth.");
    email.println("");
    email.print("Time: ");
    email.println(datetime.date());
    email.println("");
    email.println("Your treasure is being taken away.");
    email.endMessage();
    
    // send email
    if(email.send() > 0)
    {
        Serial.println("Email send ok");
        return true;
    }
    else
    {
        Serial.println("Email send failed");
        return false;
    }
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Using 9 Axes Motion Shield with Arduino
Easy
  • 22
  • 3

Protip

The Arduino 9 Axes Motion Shield allows your Arduino to measure movement: orientation, acceleration and magnetic field.

LED Roulette Game
Easy
  • 10
  • 2

Full instructions

A fun pocket-sized travel game for any age. Try your luck and make the light stop on the green LED.

Guess the Number With Arduino KeyPad
Easy
  • 79
  • 3

Full instructions

A simple and funnies project with an Arduino UNO and the famous keypad shield. Arduino selects a random number, you guess the number.

Controlling Stepper Motor Precisely via Web
Easy
  • 235
  • 9

This project shows how to control the step motor precisely using micro-stepping method via Web.

Control a 7 Segment Display with a keypad!
Easy
  • 109
  • 2

Full instructions

In this project I'll show you a simple way to control a 7 Segment Display with a keypad!

Potentiometer with RGB LED
Easy
  • 36
  • 2

This uses potentiometers to control a RGB LED.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog