Nov 07 2014

Triple-Sensor Mailbox Alert

IncomingMailI built a triple-sensor mailbox alert to tell me when there is mail in my mailbox for me.

(If you’ve already watched the video, you can skip to the technical details.)

Video Script

When the mailman comes and delivers my mail, a toy mailbox inside the house raises its flag. When I go out to retrieve my mail the toy mailbox lowers its flag. If I go out again to put outgoing mail in the mailbox, the toy mailbox is smart enough to know not to raise its flag. If anything goes wrong, like the mailbox door is left open or the battery is low, the toy mailbox waves its flag as a distress signal.

It’s possible to buy mailbox alerts but they’re not smart enough. All they do is detect when the mailbox door has been opened. If you’ve opened the door to put outgoing mail in your mailbox, or just to check whether the mail has been delivered, you’ll set off the alert.

To eliminate the false alarms, I needed three sensors. First, I have a magnetic reed switch that detects when the mailbox door has been opened. Second, I have an infrared LED on the ceiling of the mailbox and a phototransistor on the floor; these detect whether there is mail in the mailbox. Third, I have a magnet in the flag and a magnetic reed switch inside the wall of the mailbox; they detect whether the flag is up, which means that any mail in the mailbox is outgoing.

I built my own mailbox so that I could protect and conceal the electronics. The magnetic reed switch that detects the flag’s position is hidden within the side wall. Wires from the door sensor, the LED, and the phototransistor are also inside channels that were cut into the wood and then closed up when the mailbox was assembled.

For the receiver, my initial plan was to have a board in a nice enclosure. A green LED would mean there’s mail, a red LED would means there’s a low battery or the mailbox door was left open, and a reset button would reset the lights. I decided that was too boring. Instead, I bought a toy mailbox at Toys R Us. I drilled a hole for an AC power cord, stuffed a DC power adapter inside the mailbox along with a slightly modified receiver board and a servo to raise and lower the flag.

Technical Details

When the mailbox door opens, a magnet in the door closes a reed switch that provides power to the microcontroller. The first thing the microcontroller does is turn on a MOSFET that’s wired in parallel with the reed switch. So even once the door is closed, the electronics will still have power.

Next, the microcontroller checks the battery power. The microcontroller is a Microchip PIC 16F1825, which has an internal fixed voltage reference. The PIC measures the fixed voltage with the analog to digital converter, using the PIC’s supply voltage (the battery) as the reference. If the fixed voltage is too high a percentage of the supply voltage, it means the battery is low. In that case, it sends a Low Battery message to the radio transmitter. This is a battery checker that requires no extra components. Thank you, Microchip!

Next, the PIC sends a message that the mailbox door has been opened. The PIC then waits for about two minutes. This is plenty of time for the mailman to take any outgoing mail, rummage through his truck to find my mail, put it in the mailbox, close the door, and lower the flag.

After two minutes, the microcontroller sends a radio message reporting the state of the flag, as indicated by the magnetic reed switch in the side wall of the mailbox. Then, it turns on the infrared LED in the ceiling of the mailbox and uses the analog to digital converter to read how much the phototransistor in the floor is conducting. Then it turns off the LED and reads the phototransistor again. If the two readings are exactly or nearly the same, it means that the phototransistor’s view of the LED is blocked by mail. If the readings are very different, it means there must not be any mail in the mailbox. The microcontroller sends a radio message indicating whether there’s mail or not.

The work’s not over yet. The microcontroller turns off the MOSFET, which should cut power to the electronics. The microcontroller then waits 5 seconds, to drain any power from any capacitors. If it’s still running at the end of five seconds, someone must have left the mailbox door open. The microcontroller sends one last radio message, saying that the door is still open. Then, it turns off all its peripherals and enters sleep mode to save power.

The receiver interprets all these messages to decide whether to raise the flag to indicate incoming mail in the mailbox, to lower the flag because there’s either no mail or outgoing mail, or to wave the flag because there’s a problem like low battery or the door has been left open.

I made two big design errors along the way. It turned out to be a mistake to use a magnet and reed switch to detect the open door. In dry weather, the mailbox door moves freely, and when the mailman opens it, the door flops open all the way, and triggers the reed switch. But in wet weather, the door expands and rubs against the sides of the mailbox. The mailman ends up opening it maybe 70 degrees, which doesn’t bring the magnet close enough to the reed switch. So I replaced the reed switch with a TM1000 mechanical tilt sensor from E-Switch.

My second mistake was that I originally powered the transmitter with three D cell batteries. That worked great on my workbench, but wasn’t powerful enough to send a radio signal from the mailbox to the house. So I added a 9 V battery that powers only the radio transmitter – the microcontroller is still powered by the D cells. Unfortunately, my check for low battery is only done on the D cells. I won’t get any warning when the 9 V battery runs down.

If you’d like the schematics or code, you can download them here. The hardware design was done in the free version of DipTrace and the software was written in C using Microchip’s MPLAB X.

1 comment

  1. Alan Parekh

    Tons of sensors! Great project idea, I like the power saving ideas.

Comments have been disabled.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'graphene_scrollable' not found or invalid function name in /home3/rea5245/public_html/wp-includes/class-wp-hook.php on line 298