Mailbox Sensor

An Internet of Things experiment


My roommates and I hardly check our mailbox. Sometimes, the mails stack up. After a while, the mails stack up. A simple device that alerts us about new mail would be helpful. 


The goal is to create a device that sends an email every time my mailbox is opened.

How it functions

The device uses an LED and a PIR sensor. Every time the PIR sensor detects motion, the LED lights up. The Particle photon is connected to the Wi-FI at home. So, the device sends an email notifying me about this event.


Particle Photon

PIR Sensor

LED ( Red ) : Motion Indication

1 Resistors 1k ohms

Jumper wires


#include <time.h>
int inputPin = D2;
int lightPin = D0;
int val = 0;                   // variable for reading the pin status
int lastMailReceivedAt = 0;
int currentTime = 0;

void setup() {
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(lightPin, OUTPUT);
  lastMailReceivedAt =;
  digitalWrite(lightPin, LOW);

void loop() {
  val = digitalRead(inputPin);  // Read PIR sensor input value
  if( val == 1 ) {
    digitalWrite(lightPin, HIGH);
    currentTime =;
    /*If condition based on 30 seconds threshold, for email notification*/
    if(currentTime - lastMailReceivedAt > 30 ) {
      Particle.publish("motion-detected","You got mail", PRIVATE);
      lastMailReceivedAt =;
      digitalWrite(lightPin, LOW);


This is my first IOT project. There are lots of room for improvement. For example, the time of day when a mailbox is opened could be used to make the sensor more efficient. The sensor can be dormant at night. The sensor and particle photon could be housed in a well designed box.

I look forward to creating cool home automation based projects in the future.

Stay tuned.