empowering creative people

Showcase Image


Getting letters and parcels is awesome, what’s not so awesome though is when you miss the postman and you don’t know if that important bit of mail arrived or not. Such a frustrating, yet mundane problem can be solved by creating an Internet of Things mailbox!

Project Description

For this project I 3D printed a miniature mailbox which allows for the proof of concept and getting everything working, however it can easily be adapted to a regular mailbox. I used the Photon development board from Particle which is a Wi-Fi enabled microcontroller platform (most mailboxes are in Wi-Fi range), however the Electron board which is 3G enabled would work just as well.

To create this project I used:

Of course to 3D print our mailbox we used a 3D printer, however any box could be used to create your project. The model I used was created by Muzikfreak772 and after scaling it up slightly in Cura, it printed well.

 Mailbox model

The goal is that when something is put into the mailbox, it will trigger an event on the Photon which will send an email saying that there is new mail and the time the mail was delivered, and also light up an LED for confirmation.

To do this, I used an LDR/LED combo which lets use create a beam of light, which when broken by something (a letter), will change the resistance of the LDR, and therefore change the reading at our analogue pin. 

The hardware for this is extremely simple, it's actually the same as the pinouts on the sample card that comes with the photon (why reinvent the wheel), but with an extra LED for confirmation on the front.

Here is the breadboard layout as taken from the Particle.io website (with an extra LED from pin D7 to mount on the front).

Breadboard layout

A bit of drilling, scraping, and hot glue later, and the LDR and LED were mounted on the sides, although I had to lower the LED position to account for the way that mail drops in.Mailbox LDR mount

Mailbox LED mount

The wires are running up the insides of the mailbox to keep it as clean as possible. 

Then I just mounted the Photon and components on a breadboard and attached it on the back using the double-sided adhesive that comes with most breadboards. Hot glue is magical, but messy.

Breadboard mount

I'd already tested the LDR and LED just mounted on the breadboard, but the conditions are different inside the mailbox, so a bit of tweaking to adjust the sensitivity was needed, fortunately the code is written so that only one variable needs to be changed to control the sensitivity. Here's the code that I wrote, as you can see it's quite simple, but it works well in adapting to different lighting conditions. The threshold for whether or not the beam has been broken is calculated based of a difference between the current LDR reading and the previous reading, divided by the current LDR reading which means that even in bright lighting conditions or shadows, it responds appropriately.

int ledBoard = D7;
int powerPin = A5;
int ldrSense = 0;
int lastLdrSense = 1024;

int beamBroken = false;
int delayTime = 3000;
int calib = 40;

void setup() {
    pinMode(ledBoard, OUTPUT);
    pinMode(powerPin, OUTPUT);
    pinMode(ldr, INPUT);
    digitalWrite(ledBoard, LOW);
    digitalWrite(powerPin, HIGH);

void loop() {
    ldrSense = analogRead(ldr);
    if ((ldrSense - lastLdrSense) > ldrSense/calib && beamBroken == false) {
        digitalWrite(ledBoard, HIGH);
        Particle.publish("Mail", "Received");
        digitalWrite(ledBoard, LOW);
        beamBroken = true;
    if ((ldrSense - lastLdrSense) < ldrSense/calib && beamBroken == true) {
        beamBroken = false;
        digitalWrite(ledBoard, LOW);
    lastLdrSense = ldrSense;
    analogWrite(led, ldrSense);

My original goal was to create something which notifies me wherever I am when mail is delivered, the best way to do this is an simple email notification. While this might sound complicated, it's actually amazingly easy. As you can see in the code I'm using Particle.publish to pubish a variable to the Particle cloud, and by using an IFTTT recipe, I can choose the device I want to target, the variable name, and tell it to send me an email when it receives that variable. Magic!

To make it a bit more like a real mailbox, I printed and laminated a cover for the front with a quick description of how it works, a slot to insert mail, and a slot at the bottom to remove the mail.

Mailbox front

Mailbox overall

So my cute little model mailbox works nicely, and whilst it could be a littler cleaner, the concept works really well. At some point I'll update this article with the same circuit installed into a real letter box and get it up and running.

Mailbox gif

Have a question? Ask the Author of this guide today!