Casey HenriksenChase Wrenn
Published

Mail Alert!

Tired of wasting time going to your P.O box when you have no mail or missing your bills because you forgot to go? Well we have the solution!

BeginnerFull instructions provided1.5 hours742
Mail Alert!

Things used in this project

Hardware components

Photon
Particle Photon
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
PIR Motion Sensor (Generic)
×1
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Red
5 mm LED: Red
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Male/Male Jumper Wires
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

In-Home Notification Terminal

P.O. Box Sensor Terminal

In-Home Notification Terminal

Schematic Download

P.O. Box Sensor Terminal

Schematic Download

Code

P.O. Box Sensor Terminal

C/C++
This photon uses a PIR sensor to detect movement as the mailbox is opened. When movement is sensed, the activity is tracked via Google Sheets and the event is reported to the In-Home Notification Terminal. The notification terminal will send a response (confirming the two-way connection between photon devices) which illuminates the red LED on this terminal.
// PIR Sensor / Motion Detection

SYSTEM_THREAD(ENABLED); //enable multitasking.  allows the ability to catch the mailpin trigger and send the message

SYSTEM_MODE(AUTOMATIC);  //run code. then connect   

int inputPin = D0;              
int light = D4;
int pirState = LOW;             // no motion detected
int val = 0;                    // variable for pin status

int calibrateTime = 30000;   

void setup() {
    pinMode(light, OUTPUT);
    pinMode(inputPin, INPUT);  
    Particle.subscribe ("newmail", myHandler);
}

void loop() {

  if (calibrated()) {

    readTheSensor();

    reportTheData();
    }
}

void readTheSensor() {
    val = digitalRead(inputPin);
}

bool calibrated() {
    return millis() - calibrateTime > 0;
}


void reportTheData() {
    if (val == HIGH) {
        // the current state is no motion
        // announce this change by publishing an event
        if (pirState == LOW) {
          // we have just turned on
         Particle.publish("Motion", "Motion Detected", PUBLIC);
          // Update the current state
          pirState = HIGH;
                 }
    } else {
        if (pirState == HIGH) {
          // we have just turned off
          // Update the current state
          Particle.publish("Motion", "Off", PUBLIC);
          pirState = LOW;
                  }
    }
}

void myHandler(const char *event, const char *data) {
    digitalWrite (light, HIGH);
    delay(1500);
    digitalWrite (light, LOW);
}

In-Home Notification Terminal

C/C++
This Photon receives communication from the in-mailbox photon, and manages the notifications to the end user, both via phone connectivity (IFTTT/Android Alert) and visual alert (LED on breadboard).
int ledPin = D0;                // LED Pin


void setup() {
    pinMode(ledPin, OUTPUT);
    Particle.subscribe("Motion", myHandler);
}

 void myHandler(const char *event, const char *data) {
  Particle.publish("newmail", "New Mail", PUBLIC);
  digitalWrite(D7,HIGH);
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(15000);
}


void loop() {}

Credits

Casey Henriksen

Casey Henriksen

1 project • 2 followers
Chase Wrenn

Chase Wrenn

1 project • 0 followers
Thanks to Anton.

Comments