This instructable will show you how to make a web-connected mailbox sensor. Besides emailing you when your mailbox is opened, it will also signal a Raspberry Pi sitting in your house to play an audio announcement. There is also a web-accessible Android/iPhone interface for you to check what time mail was delivered, as well as display the battery voltage left on the sensor.
But this could also easily be used as a web-connected security system, one that both plays an audio alarm in your home and emails you when the someone breaks into your house.
Under normal use (a few door openings per day), the battery powered mailbox Arduino should last over a year on a set of 4xAA batteries. The transceiver has a range of over 700 feet through multiple walls, so this should work for most situations.
I'll explain how to piece all these parts together and provide all the code needed.
Step 1: Better Video Explanation Of How It Works
Take a look at this longer video to understand how the pieces of this system talk to each other. Then, we'll start the first step of making the Mailbox Arduino.
Step 2: Make Mailbox Arduino
Obtain the following parts for the Mailbox Arduino:
Follow the circuit diagram above and solder up the components. You may want to assemble a breadboard prototype to test it out before committing to a soldered strip board, depending on your comfort level. Note that there are two locations where you need to strip the copper off the strip board. Under the LED, and under the reed switch.
Burn the Arduino bootloader on the ATMEGA328P-PU using the standard "Arduino as ISP" bootloader burning instructions from Arduino here. Use the "Pro/Mini 3.3V 8MHz" bootloader.
Step 3: Create the two Gateway Arduinos
In order to receive the wireless packet and communicate the data to the Raspberry Pi, we need to use two other Arduino Uno clones. Buy an Arduino Uno clone that has a 3.3V/5V switch, and only run it at 3.3V. They're available for about $10 on ebay. One Arduino will be designated the "RFM Gateway" and the other is the "Ethernet Gateway". In the picture above, you can see the RFM Gateway Arduino on the left. It has the wireless transceiver mounted on it. On the right is the Ethernet Gateway with the ethernet cable connected. Below the two of them is the Raspberry Pi.
On the RFM Gateway Arduino, wire up the RFM69HW like this:
Plug the ethernet shield on the "Ethernet Gateway". Hook together these two gateway Arduinos for I2C:
Step 4: Download the three Arduino sketches
Download the sketches onto the three Arduinos.
To load the sketch on the Mailbox Arduino's ATMEGA328P, you'll need a TTL-USB adapter. Purchase one that as a 3.3V/5V switch if you're going to be working with RFM69HW's more in the future. Alternatively, you can use one of the pre-built Arduino Unos to program the ATMEGA328 following these instructions.
Step 5: Install and configure two programs on Raspberry Pi
Two programs need to be installed on the Raspberry Pi. One is the MQTT broker called "Mosquitto". The other is the program that runs the interface, called OpenHAB.
Next, there's some configuration needed on OpenHAB. Use the text file attached to this step and copy and paste into the different configuration files indicated.
Step 6: Assemble and Install
You can get creative with how you want to assemble and mount the Mailbox Arduino. Put electrical tape under the strip board to prevent electrical shorts. Put a case around it to protect it from water. I used magnets and velcro to mount the assembly.
Step 7: Install the Mobile App
Install the OpenHAB Android or iPhone app from the app store. Or, you can access the web interface via browser by just going to the IP address of the Raspberry Pi. Of course, you'll need to open up a port on your router to make this accessible from the internet. Have fun! This doesn't have to be for your mailbox. This also works well as a door/window alarm.