Get a Notification when Mail is Delivered

A simple email notification sent by Cayenne and triggered by a PIR motion sensor (connected to a Node MCU ESP8266) powered by a USB power bank.

Paste the device token into the Arduino code.
Add your SSID and Password to the Arduino code as well.
And upload to the Node MCU ESP8266 .

#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

#include <CayenneDefines.h>
#include <BlynkSimpleEsp8266.h>
#include <CayenneWifiClient.h>
#include <Arduino.h>
#include <SoftwareSerial.h>



// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "";
char ssid[] = "";
char password[] = "";

// Virtual Pin of the Digital Motion Sensor widget.
#define VIRTUAL_PIN V1

// Digital pin the motion sensor is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
int motionSensorPin = 4;

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
 
}

void loop()
{
  Cayenne.run();
  checkSensor(); 
}


int previousState = -1;
int currentState = -1;
unsigned long previousMillis = 0;

void checkSensor()
{
  unsigned long currentMillis = millis();
  // Check sensor data every 250 milliseconds
  if (currentMillis - previousMillis >= 250) {
    // Check the sensor state and send data when it changes.
    currentState = digitalRead(motionSensorPin);
    if (currentState != previousState) {
      Cayenne.virtualWrite(VIRTUAL_PIN, currentState);
      previousState = currentState;
    }
        previousMillis = currentMillis;
  }
}

Plug the Node MCU ESP8266 into your power bank.


Connect power and ground to your PIR motion sensor (depending on your sensor you may need to provide 5V from the power bank) and the signal out to Pin D2 of your Node MCU ESP8266 .

Add the digital motion sensor to Cayenne after the device connects.
Make sure to select your “Arduino”-(Node MCU ESP8266), Virtual Pin, and Pin V1.

Click the top right drop down and add a trigger.
Drag your ''Arduino"- (Node MCU ESP8266) to trigger and add your email to notify.


Place in your mailbox for the unsuspecting mailman.

Enjoy that feeling of knowing your package has arrived safely in your mailbox from anywhere in the world!

I would like to thank Cayenne for sponsoring this project and Chao @Electrodragon for some amazing and cheap parts (that I hope arrive soon) !

2 Likes

Hi Brandon,

Cool project, just gave you the participation prize!

-B

1 Like

Hi,

Good idea,
Do you have any problems to output the Wifi signal from the metal mailbox ?
And what is the WiFi range of the Node MCU ESP8266 ?
My home with the Wifi router is more than 50 m from the metal mailbox.

Thank’s

1 Like

nice job!!

Help me out.

This notifies you by email when you shake the sensor or it shakes the sensor when email arrives?

It sends email when the sensor shakes. right?

this is how PIR works https://howtomechatronics.com/tutorials/arduino/how-pir-sensor-works-and-how-to-use-it-with-arduino/