The SmartPostBox Project
Wouldn’t it be fun to get an email notification when your mail arrives in your post box? In this article, Andrei steps you through the details of building his ArduinoSmartPostBox project. This system is a smart post box implementation that uses a laser, a photoresistor and IoT technology to turn a regular post box into an intelligent post box that notifies you via email whenever you get mail.
ArduinoSmartPostBox is a smart post box implementation that allows you to turn a regular post box into an intelligent post box that notifies you via email whenever you get mail. This way, you will be able to open that letter you were waiting for exactly when it arrives.
Mail has been around for hundreds of years. The idea of getting letters and parcels delivered to your home is part of our long history. The US Postal Service was launched in 1775 as a means to allow individuals and organizations to send letters and packages to a central location to then be distributed to the receiver’s location.
But, mail delivery has been around for much longer. A system was first implemented by ancient Egyptians around 2,000 BCE. Letters would be placed in secure boxes and guarded by employees as they were transported on the River Nile and then on camel backs across the country.
Note: Although the terms “mail box” and “mail” are the more familiar terms in American English, in order to be consistent in this article we’re (mostly) using the British English terms “post box” and “post.”
YOU’VE GOT MAIL
Receiving a letter in the mail always gives you that bit of excitement and of wonder about what is in it. Could it be that postcard from your friend in France you were waiting for? Or another over-inflated electricity bill? There are times when I’ll get an email telling me that a letter will arrive today that I have been expecting for a while. This would get me very excited and sometimes, I might even lose focus and daydream about getting it.
In my case, I can’t look out the window to see when the post man arrives and so I’d need to go out and check to see if there’s something in the post box. This is quite stressful and makes me less productive. I would love to be notified when mail arrives—whether I’m at home or at work. Knowing that I’ll be notified exactly when the post arrives would prevent me from stressing over its delivery.
— ADVERTISMENT—
—Advertise Here—
So, I designed ArduinoSmartPostBox (SmartPostBox for short) to tackle this issue. This project consists of a device that is placed within the post box and detects if a letter has been placed in the box. The device will check for the presence of a letter at intervals of time and send an email to the user when a letter was detected. The device is designed to slide into a post box, sitting on the bottom of it. In Figure 1 you can see the gray of the SmartPostBox device through the open slats at the bottom of the post box.

SmartPostBox shown closed. You can see the gray of the SmartPostBox device through the open slats at the bottom of the post box.
The device uses a laser and a photoresistor arranged at opposite sides of the post box. When a letter is inserted in the post box, the beam shining at the photoresistor will be blocked and that way the device can detect that a letter was placed in the box.
The device will then connect to the backend and issue the command to send an email to the user saying that they received mail. The user will receive a notification right after they received mail allowing them to know when to go out to get the mail. SmartPostBox brings IoT connectivity to post boxes, allowing any existing post box to be enhanced using the implementation. This enables people to get notified when their mail arrives so they can pick it up right away. SmartPostBox can be implemented on a personal or wide scale with ease. Figure 2 shows the email the user receives when they received mail.
ARDUINO MKR FOX
Now let’s dissect the project and talk about the specifics. For this project, I used the Arduino MKR Fox microcontroller board shown in Figure 3. The device is an Arduino board from the MKR family. These boards feature a small form factor and great battery life while maintaining the same performance available on other boards. The device operates at 3.3V, as opposed to 5V, which reduces power consumption. The processor is also equipped with a low-power mode that enables it to hibernate for set periods of time. This also improves the battery life significantly.
The Arduino MKR Fox has Sigfox connectivity built in. This allows the device to connect to the Sigfox network and send small data parcels to the backend. Sigfox defines a communication protocol that allows devices to send very small data packets over the Sigfox radio infrastructure. This reduces battery consumption drastically. That’s because the packets sent are under 12 bytes and communication is unidirectional, meaning that energy can be conserved through this means as well. Finally, the device is issued by Arduino and can be easily programmed through the Arduino IDE using the C++ language.
The device has a beam-breaking system in place, which enables it to identify if a letter has been placed in the post box. This implementation consists of a small laser module and a photoresistor placed on opposite sides of the post box. This is illustrated in Figure 4 by the dotted red line. The laser is perfectly aligned with the photoresistor. This causes a beam of light to be transmitted from the laser to the photoresistor. If a letter is placed in the post box, it will come between the laser and the photoresistor, this would cause the beam to break and the light would no longer reach the photoresistor.
The Arduino MKR Fox reads the analog value outputted by the photoresistor to see if the light beam is broken. If it is, the MKR Fox will send a message to the backend informing that a letter has arrived. This process is repeated every time the device wakes up from sleep.
I designed an enclosure for the project so it can easily be placed in a post box. The dimensions of the enclosure depend on the post box in which the device is to be placed. I designed it for my post box, which is a standard issue United Kingdom (UK) post box. I’m aware that a lot of people, in the US for example, would have different dimensions and styles of post boxes. It’s up to you to design the enclosure and make it so that it can fit in the post box and that the letter inputted would block the light beam appropriately.
Figure 5 shows a rendering of the enclosure I built. The enclosure is composed of an M-shaped outline. This would be placed on the bottom of the post box. The V shape at the top allows for the letter to slide into the bottom of the enclosure. This ensures that the letter obstructs the light beam and triggers the system. The letter is also easy to extract from the post box thereafter. I’ll get more into the specifics on constructing the enclosure later in Step 7: Constructing the enclosure.
— ADVERTISMENT—
—Advertise Here—
SIGFOX CONNECTIVITY
The Arduino MKR Fox has built-in Sigfox connectivity through an onboard Sigfox module. This enables the device to connect to the backend with ease. Sigfox is a communications company that aims to create infrastructure that helps low power IoT devices send small packets of data through the infrastructure and then link custom web apps to perform actions with the data in the backend.
I chose to use Sigfox connectivity because it is a low power protocol and its small packet sizes are perfect for the project. The device does not need to send any data to the backend but only a notification that there is post. Using other protocols such as GSM or Wi-Fi would require more power and are better suited for devices sending more data.
Messages sent by devices through the Sigfox network are centralized in their server. This data is accessible through the online portal. Sigfox allows for callbacks to be implemented. These essentially allow other applications such as a mailing service or a cloud service provider such as Amazon’s AWS to be integrated in the backend. When a message arrives in the backend, a callback can act on this message. This project uses the built-in Sigfox email callback to send an email to the user whenever a message is received from the device. The email is sent within seconds from the device detecting the post.
Security and data protection is very important when dealing with IoT devices. The device does not send any sensitive data across the network. The device does not need to get its location or other sensitive data and is unaware of this information. Therefore, if an attack were to take place, no sensitive data would be obtainable. All backend solutions are provided by Sigfox. The email callback is also issued by Sigfox hence the message sent by the device does not exit the Sigfox ecosystem in the backend. This ensures that the message sent by the device stays within the Sigfox backend and cannot be obtained by unwanted third parties.
SLEEP AND BATTERY LIFE
The device was constructed with longevity and extended battery life in mind. This is important with a project like this because it would not be convenient to constantly have to change the batteries. The Arduino MKR Fox runs on just two AA batteries. These batteries are placed in a battery holder, which is connected to the device via the terminals.
The MKR Fox can last for about two to three weeks on the batteries before they would need to be replaced. A combination of features allows for the extended battery life. The chip will check if the light beam is obstructed and then go to sleep for 10 minutes. This sleep mode exponentially increases the battery life of the implementation.
The Sigfox communication protocol also increases the battery life significantly because it requires minimal data exchange meaning that the device does not need to send or receive large data packets. The battery life could be extended by powering the device with a power bank if desired.
PROJECT ARCHITECTURE
Now let’s delve into the project’s architecture. The project is split into two sections: the frontend and the backend. The frontend refers to the IoT device checking for mail in the post box and the backend is the Sigfox server and emailing service.
Figure 6 shows the architecture of the frontend. The MKR Fox will wake up from sleep mode and immediately get the light intensity value from the photoresistor. This will allow it to check if the laser’s beam was obstructed by a letter. If this is the case, the device will send an empty message to Sigfox and return to sleep. If not, the device will go to sleep without sending a message. The process is repeated when the device wakes up every 10 minutes. The device will remember if an email was sent and will not send another until the mail is removed and new mail is received.
Figure 7 shows the backend architecture diagram. The message sent by the device is relayed to the backend via Sigfox telecommunication towers. Once it arrives in the Sigfox backend, a callback is immediately executed, which triggers an email being sent to the user. The email is event based triggered, hence the email to the user will be sent immediately as the message reaches the backend.
MARKET AND COSTS
Let’s move on to discuss the product in the marketplace and the costs of deploying the device. SmartPostBox can be mass produced and implemented in post boxes sold on a wide scale. A company may choose to create a range of smart post boxes and incorporate the project to modernize their existing stock and sell it for a premium. This would allow the company to use existing post boxes already constructed and add the feature to get an email whenever you get mail for an extra cost for interested buyers. All they would have to do is place an SmartPostBox device inside a pre-existing post box.
The product is targeted at a wide audience. The target audience consists of middle- and upper-class individuals who are interested in home automation solutions. The product is limited to the countries where Sigfox can operate as the project is reliant on the technology.
Here’s an example of typical user: John is a man living with his wife in a house in a suburb in Dublin, Ireland. He is invested in home automation and hears about a company providing smart post boxes that can send him an email whenever he gets mail delivered. He is very interested in this solution and opts in to purchase an upgraded post box with this feature.
The project’s costs are very reasonable. The project has been designed to be 100% open source. All the code and design files are available on GitHub [1] for free. This enables anyone around the world to use the design files and code to help them launch their own version of the product. Free software can also speed production as there are no legal hurdles in the way.
Sigfox is available in regions in more than 80 countries worldwide including North America and most of Europe. Sigfox relies on infrastructure constructed specifically for this protocol to be implemented for the system to work. Most major cities around the world are covered by Sigfox and some countries are covered nearly in entirety. Before starting to build the project, you should check if the country you live in supports Sigfox by checking out their coverage map [2].
— ADVERTISMENT—
—Advertise Here—
Table 1 shows an approximation of costs for developing one device. The cost analysis includes the MKR Fox retailing for about $47 (€40) depending on the region as well as the cost of other components used in the project. The cost analysis also includes the cost of designing and constructing the enclosure together with the estimated cost of labor required to manufacture one product in a supply chain. All components used in the project are off the shelf and hence the price per unit drops as quantity produced increases.
Table 2 shows the recurring costs for deploying one unit. There are two main costs summarized on a monthly basis. Batteries are required for the project. The project will run out of power every two to three weeks. The cost of one-and-a-half battery replacements is included in the cost (three AA batteries). Using rechargeable batteries is more cost-efficient and environmentally friendly.
The project also needs Sigfox backend costs to be paid. Sigfox has very flexible plans that allow device connectivity on a yearly basis for a set fee. The plan is paid yearly and the cost averages out to just 50 cents per month. This operation cost is very cheap. The MKR Fox also comes with a 2-year Sigfox connectivity certificate so this cost would only incur afterward. Overall, the cost of operation is estimated at $4.12 (€3.50) a month.
PROJECT CONSTRUCTION
This section will talk about the steps needed to construct the project from start to finish and everything needed to construct it. Please note that before starting to order components and built the project, it is essential to check if your country is currently covered by Sigfox on their coverage map [2].
Step 1: Required components: This project requires a small amount of electronics. The list of required components is listed below, and shown in Figure 8.
- 1 Arduino MKR 1200 Fox [3]
- 1 Laser module
- 1 resistor (1KΩ)
- 1 photoresistor
- 1 2x AAA/AA battery box
- 2 AAA/AA batteries
- Jumper wires
Step 2: Connecting the circuit: The electronics diagram for the project is shown in Figure 9. There is no breadboard in the project so the connections are a bit jumbled up. Use a soldering iron to solder the components as shown in Figure 9. You can place the batteries in the battery holder now and connect the antenna to the MKR Fox via the onboard connector. Don’t connect the batteries yet, we will do this after the program on the device is ready to go.
Step 3: Setting up Sigfox: Before continuing with this guide, you will need to follow the Arduino “getting started” tutorial [4] for the MKR Fox. This walks through creating your Sigfox account and connecting the MKR Fox to the backend. After you finished going through the guide, you can continue here.
- To get started, visit backend.sigfox.com and sign in
- From the Sigfox portal, click on Device Type from the menu at the top of the screen
- You should see the list of your devices now. Click on the device you are working with
- From the next window, select the Callbacks option from the menu on the left of the screen
- Click on the New button in the top right of the screen to create the email callback
- Select Custom Callback from the list provided
- Now configure the callback as shown in Figure 10
- Click OK and you are ready to go!
The {device} keyword is a variable representing the device’s ID, it is a built-in variable, there are many more of these like {lat}, {lng}, {time} and others, you can insert them in the email’s subject or body by just pasting them in from the menu above. You can customize the content of the email if you wish.
THE SOFTWARE
Step 4: Acknowledging the code: There are two main functions in the project’s code: “Read and Analyze Photoresistor” and “Send Packet.” These are each explained here. Please clone the code from the GitHub repo [1] to follow along.
Read and analyze photoresistor: In Listing 1, the first line of the section reads the photoresistor’s analog value, which is connected to pin A1, if the value is smaller than 800 (out of 1,024), and if the value dropped now and was not previously below 800, it will run the Send Packet function. If the value is above 800, the Arduino will reset the Boolean variable pos (which stores if the previous value was below 800), if the previous value was smaller than 800 (Indicates presence of a letter), the Arduino will wait until the letter is removed.
Listing 1
Code for reading and analyzing the photoresistor’s analog value
lightIntensity = analogRead(A1); // read the photoresistor value
if(lightIntensity < 800)
{
if(pos == 0) // if not pending removal
{
pos = 1;
…
Send packet: This section of code in Listing 2 will send a packet to Sigfox if mail is detected, the Arduino will start the parsing procedure and will print ” ” (space) to Sigfox, it will wait for confirmation that Sigfox received the message and will then wait for the letter to be removed. It will then start the algorithm again.
Listing 2
Code for sending a packet to Sigfox
SigFox.beginPacket(); // start the sending protocol
if(proDebug)
{
Serial.println(" Parsing Packet");
}
SigFox.print(" "); // print a constant character to send
int ret = SigFox.endPacket(true);
// wait for SigFox to receive the packet
Step 5: Setting up the variables: There is a single variable that the user has to set, proDebug. If it is enabled, the Arduino requires connection through USB to a computer and the Serial Monitor must be open, the Arduino prints to the Serial Monitor in this mode, it is ideal for troubleshooting. proDebug defaults to 0 for operating on the field.
Step 6: Debugging and calibrating: The next thing to do now that the code is ready to go is upload it to the MKR Fox. Ensure the device is plugged into your computer and the right board and connection are selected through the IDE. You can now compile and upload the code to the device.
Run the device with proDebug set to true the first time to see if you get any errors. There is a chance the code may seem to crash after the parcel was sent to Sigfox. This is a quirk with the Serial Monitor and the device should work perfectly on the field with proDebug set to 0. Before debugging, I would comment out the last line that instructs the device to go into sleep mode and add a 5 second delay, as follows:
delay(5000);
I suggest you align the laser and the photoresistor such that the light from the laser shines directly on the photoresistor a few centimeters apart. I would then check the reading of the photoresistor in the serial monitor (it could be anywhere up to 1,024). Ideally, the reading should be above 800 or so when the laser is shining on it and lower when it is not. This may not be the case in a light room, but don’t worry, the post box should be dark enough.
If the values greatly differ, you may want to check the wiring. For example, if the laser is shining on the photoresistor but the value is too low, it may indicate that there is an error with the wiring. If the value of the photoresistor when the laser is shining on it is close to 800 but not always greater than it, I would reduce the threshold. This can be done by altering line 80 in the code.
You can also check if the MKR Fox is sending messages to Sigfox successfully. If all the setup went well, you should be getting an email every time the photoresistor breaks contact with the laser. You can also monitor the device by going into your Sigfox portal and then selecting Device > Choose the Device > Statistics. You should see a graph with the data sent by the device to the backend like the one below. This proves that the MKR Fox is sending data to the backend. Figure 11 shows an example of this populated graph. After all this is done, ensure to set proDebug to 0 and upload the final version of the code. Nearly there!
Step 7: Constructing the enclosure: The last thing to do is create an enclosure to place the components in and then place inside the post box. I chose to create the enclosure out of cardboard to test it out as it was easy to bend it in order to fit inside the post box.
I would personally recommend either cutting out the pieces needed to construct the enclosure or 3D printing it out of a plastic such as acrylic. All design files are on the GitHub page [1] as previously mentioned. Ensure you measure the dimensions of your post box and adjust the enclosure to fit them.
You will need to drill two holes into the enclosure directly opposite each other and glue the photoresistor and laser aligned. You can keep the device on while doing this, so that you have a visual representation of where the laser is shining and if it is aligned with the photoresistor. Figure 12 is a drawing of the enclosure.
And that’s it, you’re done! All the components can go within the M-shaped enclosure, they should be hidden in the post box. Figure 13 shows a postman putting post in a post box powered by SmartPostBox.
REFLECTIONS
I created ArduinoSmartPostBox because I wanted to expand the idea of home automation to things that are outside the home such as the post box. I always found it a pain to have to go outside just to check the mail to see if I received anything.
I wanted to modernize the post box and empower it with IoT connectivity. I decided to create a project powered by the Arduino MKR Fox that would identify if mail was placed in the post box. I began by brainstorming ways the device would detect the post in the post box. After a bit of thinking, I decided to use a laser and photoresistor to create a beam. The mail would come in between the laser and the photoresistor changing its reading, hence identifying the mail.
The hardest part of the project was building the enclosure as my post box is quite tight and it is difficult to fit everything in. In the end though, I did manage.
RESOURCES
References:
[1] SmartPostBox GitHub page. https://github.com/Andrei-Florian/SmartPostBox
[2] SigFox coverage map. https://www.sigfox.com/en/coverage
[3] Arduino MKR 1200 Fox board https://store.arduino.cc/usa/arduino-mkrfox1200
[4] Arduino getting started tutorial for the MKR Fox https://www.arduino.cc/en/Guide/MKRFox1200
Arduino | www.arduino.cc
Sigfox | www.sigfox.com
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • MAY 2021 #370 – Get a PDF of the issue
Sponsor this ArticleAndrei Florian is a student in Dublin, Ireland. He has been working on tightening the connection between humans and technology by designing applications that will help us in our lives. This includes working on projects that combat pollution and climate change as well as monitoring our natural environment and our cities. He has also been working on personal security and big data. Andrei can be contacted at andrei_florian@universumco.com