Introduction: Build a Letterbox That Sends You Alerts.

About: MickMake is a YouTube channel by a Maker for Makers. Complete with reviews, tutorials, technology explanations and my popular Weekly Roundup of New Maker Products. Subscribe to get notified of the bi-weekly vi…

This instructable has several videos that accompany it, they are:
Building an MQTT letterbox Part 1

The MQTT letterbox Part 2: Sending alerts from MQTT

I also suggest checking out my other MQTT videos:

What Is MQTT?

MQTT Mosquitto on a Pi Zero W in under 5 minutes

You can also find these links on my website or at the end of each video.

Step 1: The Parts List

So I need to be able to detect every time someone puts a letter into the box and also detect the movement of the rear flap, indicating someone has removed letters. Being able to do this without having to destroy the letter box and have it work reliably, was hard.

I want to avoid any microswitches as they are more exposed to the elements, are messy and can be unreliable. So a sensor was needed that could respond to something moving from a distance. I didn't want to use a PIR as I may get false readings, especially if the back flap was left open. Same story with ultrasonic sensors and most of them run off 5 volts which limits the choice of MCU. An IR shooting sensor could work, but would rely on some fiddly positioning in the mailbox. 5mA current draw was also a little high. Likewise Phototransistors would be fiddley to work with and would require more cables that I'd want.

So, I eventually settled on this simple distance sensor, which is capable of responding to an object between 20 and 200mm away. Perfect size for my mailbox and there won't be any noisy bounce or false triggers.

I also needed something on the flap that was cheap and reliable. This Fast Vibration sensor would do the trick and is dirt cheap.

It also needed to be battery operated, charged by solar, and since there's going to be an ESP8266 onboard, might as well chuck in some humidity and temperature sensors.

So, the parts list is:

On the software side there is:

Additional items you will need are:

  • MQTT Broker - you can either build one yourself, or use one of the many Internet based ones.
  • A WiFi Access Point.

Step 2: Solder Time.

In the photos you can see the end result, everything fitted well into a sold aluminum case.

I suggest breadboarding it all up first as then you'll have an idea of where everything fits.

The AM2302 humidity sensor attaches to GPIO0, (which just so happens to be the LED as well, but that doesn't matter).

The vibration sensor, (S1), connects to GPIO13 and GPIO12. GPIO12 is an input with internal pullup resistor and I used GPIO13 as a "lazy man's" ground point to avoid soldering extra wires. If you are using your ESP8266 for other things and need GPIO13, then just use any ground point instead.

The distance sensor, (SENS2), uses GPIO14 and will set this HIGH when something passes in front.

The TSL2561 I used so I could see how much sunlight was around so I could potentially drop down into ultra-low power mode to save battery when it was cloudy.

For power the solar panel connects to the LiPo charger, and then the output of that connects to the ESP8266, which does have it's own LiPo charging system, but this system allows you to charge your LiPo as well as run the ESP8266 at the same time. During overcast days the LiPo may not be charged, so the ESP8266 has to be able to run for a couple of days on a single charge.

You'll have to get creative with the stripboard and placement of components. The placement I used here minimized the number of cross-over wires that had to be soldered.

Once you have everything soldered up, of course, make sure you program the ESP8266 with my code.

Step 3: Putting It Together

Since I was using an all aluminium case and my letterbox was a fair distance from my house I had to use an external antenna. You can solder this up directly to the PCB antenna and the shield on the ESP8266 module. This greatly extended the range of the ESP8266 and I didn't see any dropouts. The external antenna connector was then screwed onto the lid of the case.

The distance sensor poked out the lid via a square hole.

I mounted both PCBs to the bottom of the case using hot glue. First place a small amount on each corner, and wait to cool. This will provide a "stand off" to avoid anything touching the case. Then place some more on each corner and place firmly into the case.

The humidity sensor also needed to be external as it'd be useless inside the case. So I drilled holes and ran the wires into the case and secured it with a small nut and bolt.

I also used some Deutsch connectors between the solar panel and LiPo charger so I could remove one or the other for maintenance. These are expensive, but are very waterproof and really something that's needed when working with solar panels.

The end result should be fairly weatherproof and self contained unit.

Step 4: Mounting It.

Mounting everything really depends on what existing letterbox you have.

I hot glued the sensor box to the roof of the letterbox so it could pick up when letters were delivered.

The solar panel I hot glued to the side at an angle to optimize pickup of solar rays.

The rear flap sensor I stuck with gaff tape.

Step 5: Setting Up MQTTwarn + IFTTT

There's a lot to mqttwarn, but the important elements that you need to add into the mqttwarn.ini file are indicated in the photos.

  • The IFTTT key needs to be the same as the Maker Webhooks key.
  • The Event name needs to correlate with the trigger field in the applet that you create on IFTTT.

Step 6: Testing

The responsiveness of the MQTT + IFTTT network is pretty decent. I found there to be a delay of between 5 and 10 seconds on an event. Pretty fast!

Internet of Things Contest 2017

Runner Up in the
Internet of Things Contest 2017