Long Distance Mailbox Alert using LoRa

You’ve got mail! An IoT project using solar power and long range radio

In these pandemic times of limited mobility, I become more like a dog every day: looking forward with great enthusiasm to meals, walks and car rides. One of the daily events that’s taken on new importance is walking down to the mailbox. But it’s over 100 yards away from the house, so it’s nice to know when there’s actually something in it to collect. So I devised a means of getting an alert when the mail is delivered.

There are simple mechanical devices that set a visible flag when a mailbox is opened but ours is too far from the house to see. And the distance exceeds the range of commercially available Bluetooth and WiFi solutions. There is no source of power near the mailbox. Running hundreds of feet of cable seemed like an expensive and impractical means of solving the problem.

I cobbled together the perfect solution using a repurposed solar-powered floodlight and LoRa transmitter/receiver pair. LoRa (Long Distance Radio) works great for sending short data packets great distances. Unobstructed range can exceed several miles. LoRa modules are inexpensive and consume very little power.

An ideal IoT solar-powered enclosure

I found a $30 solar floodlight on Amazon that is perfect for this and would be for many other IoT (Internet of Things) projects. The device has a weatherproof enclosure, two user-replaceable 2200 mAh batteries and charging circuit. One screw opens it up and there’s plenty of room inside to add your own circuitry inside. The only deficiency I see with this product is that it lacks an O-ring or other means of weatherproofing, although the Amazon product page claims it is IP65 splash resistant.

Interior of solar panel before any modification

The project is described below in detail below in case you want to build something similar

Project Summary

A pair of LoRa radios is used for this project, one as transmitter and the other as receiver. The transmitter spends most of its time in low power mode with the radio sleeping. In that state it draws only around 10 mA. We’re powering it from the solar panel’s two 2600 mAh batteries, enough to power the module for 500+ hours. That’s a lot of cloudy days!

Whenever the state of the connected switch changes, the transmitter sends a short string of text: “1” indicating open or “0” for closed, followed by a space then the battery voltage. For example, “1 4.07”. The receiver listens for these packets. When one is received, an LED and/or servo are activated.

The LoRa module also echos the message to its serial port for interfacing with other systems (more about that in the next post).

Keep in mind that this project could be adapted for many other open/closed, true/false monitoring scenarios, e.g., driveway gates, doors, motion alarms, etc.

Bill of Materials

  • Hikeren Solar Light or similar
  • Pair of LoRa32u4 development boards like this set
  • An ESP8266 WiFi board (optional) like the D1 Mini (see next post)
  • Magnetic reed switch like the kind commonly used for alarm systems or other suitable contact for mailbox door
  • 10K pull-down resistor (exact value isn’t too important)

Arduino code is located at: https://github.com/RatRanch/Long-Distance-Mailbox-Alert

Assemble the Transmitter

  1. If you haven’t yet set up the Arduino IDE for use with your LoRa32u4 board, follow along with this guide. The setup only needs to be performed once.
  2. Upload the mailbox_transmitter sketch to one of the LoRa32u4 boards.
  3. Open the solar panel enclosure by removing one screw
  4. If you are attaching an external antenna, drill a 6mm (1/4″) hole in a suitable location and attach the antenna. Use an O-ring or some silicone sealant to keep it watertight.
  5. Clip the wires that attach the LED floodlight–which isn’t used for this project–to the circuit board. We will be using this cable to connect to a switch instead. Attach these wires to pins 5 and 3V3 (polarity doesn’t matter) and attach 10K pull-down resistor between pin 5 and Gnd. Solder these connections.
  6. Mount the LoRa board above the existing charging board. You can use two of the existing screw holes with spacers or a piece of double-sided tape. Make sure the charging and LoRa boards aren’t touching each other (I used a piece of Kapton tape as an insulator).
  7. Attach positive and negative power leads to the corresponding battery rails.
  8. Then re-attach the enclosure cover. Make sure the power switch on the back of the case is in the On position.

    The completed transmitter assembly interior should look something like this:
Installed LoRa Board

Here’s the installed transmitter assembly:

Installed LoRa Transmitter Assembly

Assemble the Receiver

  1. Upload the mailbox_receiver sketch to one of the LoRa32u4 boards. The code repository is here.
  2. If you just need an indication of when the mailbox is opened, you can stop here. The built-in LED will alternate between on and off every time the mailbox is opened. You could optionally connect an external LED to pin 13.
  3. Or you could have a little more fun and make an enclosure for the receiver. With a working flag that goes up when mail is delivered!
  4. You can more or less follow the instructions here to print and assemble the mailbox enclosure and mount the flag servo. The mounting holes don’t quite line up with the LoRa board but I had good results mounting it with only one screw. Double sided tape would also work fine. A nice remix of the design is here if you want a post and stand.
  5. Solder three wires from the servo to the LoRa board. Power positive goes to the 5V pin and negative to the Gnd pin. The signal wire gets attached to pin 11.
  6. Short pin 5 to 3V3 (or install a momentary switch between these pins) to test the servo action and align the flag.
  7. There is just enough room in the mailbox to fit the “rubber duckie” antenna that comes with the LoRa board if you rotate it to the 90 degree position. Cover the metal portion of the antenna with heat shrink tube, tape or whatever to prevent it from shorting the circuit board. You could also use a 78mm length of wire as an antenna but the range won’t be as good.

Operation

There’s really not much to it. 🙂

When the receiver is powered on, the flag will rotate clockwise to its down position. Every time the contact switch attached to the transmitter closes, the flag will toggle position. If you’re putting mail into your mailbox for collection, you can just open and close the mailbox door an extra time to reset the receiver flag to its down position. Or cycle power to the receiver, which will also reset the flag.

In the next post, I’ll describe how I interfaced the mailbox receiver with the awesome Indigo Smart Home Software platform. It sends a text message to my cellphone when the mail arrives.

Technical note: conflict between servo and RadioHead libraries

The RadioHead library is used to operate the LoRa 32u4 RFM95 radio. Out of the box, this conflicts with servo.h, which we would normally use for projects involving servos (more details here).

One solution is to modify the RadioHead library to eliminate the conflict by using a different hardware timer, however, I wanted to make this project easy for others to implement.

You’ll note that I’ve “rolled my own” soft servo control code in the mailbox_receiver.ino sketch (moveServo() function). This technique would not work well if any degree of precision is required but we’re just concerned about moving the flag 90 or -90 degrees for this project. Unlike other examples I found on the web, this function sends multiple positioning pulses instead of just one to prevent position drift.

Leave a Reply

Your email address will not be published. Required fields are marked *