Smart Mailbox With Website
by KobeClaeys in Workshop > Home Improvement
178 Views, 1 Favorites, 0 Comments
Smart Mailbox With Website
I was looking for a compact way to receive letters. I also wanted to be notified when I got some letters. That's when I decided to make a smart mailbox.
Requirements for my mailbox were:
- Compact
- Easy access to components
- Modern looking design
In this instructable I will show you step for step how I made my mailbox.
Supplies
Raspberry pi 4B (+
My project was made with a raspberry pi 4b. It might be possible to use an older version of the pi (3 for example).
Magnetic door sensor
Like this one! It is used to detect when someone opens the lid of your mailbox.
16 x 2 LCD-display
An LCD display, controlled with an (external) PCF8574 to display your IP, and whether there is mail in your mailbox.
PCF8574
Used to control your LCD, so there are more pins available on the raspberry. It is also possible to buy an LCD with an I2c module already installed.
Potentiometer
A simple potentiometer to change the brightness of the LCD screen.
5 Laser diodes (+ 5 220 Ohm resistors)
5 laser diodes, each with a 220 Ohm resistor. They are connected to the external 5v module (see electrical scheme down below) and are used together with the LDRs to detect if you have mail.
6 Light Dependant Resistors (+ 6 10k Ohm resistors)
LDRs measure the brightness of the space around it. 5 LDRs have the lasers shining directly on them, so when the laser is interrupted, the LDR will notice. the other LDR is used to turn on the led strip inside the mailbox when it's dark outside.
MCP3008
The MCP3008 is an 8-channel 10-bit analog to digital converter with the SPI interface. It is used to read the data from the 6 LDRs.
RFID RC522 reader
The RFID reader is used for 2 purposes. The first one is to open the lock of your mailbox. The second is to log in to your account on the website.
4 pushbuttons
- To turn the Raspberry Pi on
- To turn the Raspberry Pi off
- To display the IP on the LCD
- When you've emptied your mailbox
220 AC - 5 VC and 12 VC converter (or 1 for 5v and 1 for 12v)
A simple converter to go from the 220v AC from your outlet to 12v for the lock and 5v for the led-strip and lasers.
5v led strip
A simple white 5v led strip.
Transistor
An NPN transistor (I used the 2n2222) to control the led strip.
3.3v relay (3.3v signal, at least 12v for doorlock)
A relay that turns on / off with a 3.3v signal (from the Raspberry Pi). It has to be able to handle at least 12 v since it is used for the door lock.
Solenoid doorlock
A solenoid door lock to lock/unlock your mailbox.
GPIO T-part
A t-part for your raspberry for easier connections.
(solderable) breadboards and copper wire
to connect all the devices.
Wooden MDF planks (width: 1cm)
To put the whole thing together.
Downloads
Cutting the Basics
Cut your wood to the right size. What you need:
- 4x planks of 30 x 60cm each (1)
- 4x planks of 28 x 4.5 cm each (2)
- 1x plank of 30 x 30 cm (drill holes some holes in this one) (3)
- 1x plank of 31 x 31 cm (for the top lid) (4)
- 1x plank of 27.5 x 27.5 cm (for the top lid) (5)
- 1x plank of 26.5 x 7 cm (for the lid) (6)
- 1x plank of 48 x 27.5 cm (for the inside) (7)
- 1x plank of 40 x 27.5 cm (for the inside) (8)
- 1x plank of 40 x 22 cm (for the inside) (9)
- 1x plank of 10 x 22 cm (for the inside) (10)
- 1x plank of 5 x 21.5 cm (for the inside) (11)
- 1x plank of 26.5 x 21 cm (for the inside) (12)
Making the Outside
Put the 4 30cm x 60 cm planks to each other.
Choose your front side. Cut a rectangle from x by x in the middle. It has to be down 5cm from the top.
On the left panel (from the front), cut a 20 by 5 rectangle, 10 cm up from the bottom (it is too low in the pictures).
Put a 27.5 by 27.5 plank in the middle of a 31 by 31 one, like in the first picture. This will be the top lid of your mailbox.
Make a rectangle on the back of your mailbox to fit the LCD. You will have to sand the sides a bit to make it fit perfectly (pictures 3 and 4).
Making the Inside
To make sure the electronics are accessible at all times, the mailbox will consist of 2 layers that are separate from each other. That way, you will be able to access the electronics all the time.
Attach the 48 x 27.5 cm (7) and 40 x 27.5 cm (8) planks opposite to each other on the 26.5 x 21 cm plank (12).
Put the 40 x 22 cm (10) plank on the right side of plank 8 and the 10 x 22 cm plank (9) on the left.
Make the 5 x 21.5 cm plank (11) skewed so the letters slide into your mailbox. Put it in the middle of plank 8.
Making sure the inside fits
To make sure it fits. Put 4 pieces of wood (height: ~9.5cm) on the bottom of our outer box (2 on the front side, 2 on the back: see 2nd picture).
The next part is to make sure the inside part is centered. TO do that, just put 4 equal wood planks in each corner of the outer part (picture 3).
Making the Door and Lid
On the back of your door, put a little metal cover to block the door from going in (see picture 1). Make sure to put it on the other side where your hinges are!
Installing the door
Make 2 little notches on the left side (picture 2). Put the 2 hinges in the notches and onto the door part (picture 3).
Installing the lock
After that, put the solenoid lock on the backside of your door (see picture 4). If you want the door to be aligned perfectly with the rest, you will have to glue a little piece of wood on the side. You will have to cut a little piece out of the floor of the inner part (see picture 5). After that, just put a little handle on the door.
Installing the lid
Put a long hinge just above the opening for the lid. If you want to make the lid go higher, make the top skewed (picture 6). Make a little slope and put it on the inner part of the box (picture 7).
Putting the Components In
Lasers + LDRs
- Drill 5 holes for the laser on the inner part (backside, picture 1) at around 36 cm starting from the bottom.
- Drill 5 holes for the LDRs on the other side.
- Connect the lasers to a power source (with resistor!) and make sure they are aligned correctly with the LDRs (picture 2). Glue them in place.
LCD
- For your convenience: Put all female - male wires on the pins of your LCD and put them together with duct tape.
- Screw the LCD in place
Buttons
- Make for holes in the outer part of your mailbox (pictures 3 and 4) (2 on the backside, 1 on the left, right to the LCD), and 1 in the inner part( on the bottom plank of the inner part, accessible when you open the mailbox)(picture 5).
- Put the cables in and glue the buttons into place.
RFID-Scanner
- Put the fourth pin (starting left from the backside) upwards for convenience. Put the female-male wires onto the pins and put them together with duct tape (picture 6).
- Screw the RFID-Scanner in place.
Magnet sensor
- Screw the wired part onto the side
- Screw the unwired part on the lid itself (make sure it is close enough to the wired part) (picture 7).
Led strip
- Paste the led strip on the bottom side of the plank on the side of the door (picture 8).
Wiring
I recommend using print boards, but you can use breadboards as well. Just make sure your cables don't come loose easily. Follow the schema and make sure to use the correct pins!
Installing the Pi
Putting the Pi in your case (recommended)
Put your pi in a case with cooling to make sure your Pi stays cool and doesn't shut down due to heat.
Configuring your SD card
- Download Raspberry Pi Imager (if you don't already have it of course)
- Install Raspberry Pi os on an SD card of at least 8 Gb
- Go to your Raspberry Pi's directory and open cmdline.txt
- Type 'ip=192.168.168.169'
- create a file 'ssh' without extensions
- Save the file, safely remove the sd-card and put your sd-card
Configuring your Pi
- Make your Pi ready
- Plug an ethernet cable in your Pi and pc
- Connect via putty (download here) with ip: 192.168.168.169
- login with default username / password (pi / raspberry)
- Type sudo raspi-config and press enter
- In the menu, select advanced (6) > Expand Filesystem (1)
- Reboot your Pi
- Add wifi access
- Type sudo -i and press enter
- Type wpa_passphrase
Installing the code
Setting Up the Database
Database design
There are 3 main info tables. The first one is 'historiek', which has all sensor data. The second one, 'brievenbusevent', has all the important info we want to display to the user. The last one is 'gebruikers'. This table contains all info about users. 'SettingsChange' makes sure we can use the latest settings when our Pi restarts.
Database implementation
To implement our database, open MySQL workbench. Then, you'll want to create a new connection to your Pi. Fill in the details like in picture 2, and follow these steps:
Start MySQLWorkbench on your laptop and open a new connection
- Choose Standard TCP/IP over SSH for Connection Method
- SSH Username: pi (unless you've changed it)
- SSH Password: raspberry (unless changed)
- Username: pi (unless changed)
- Password: raspberry (unless changed)
When you've filled it in, you can try with 'test connection'.
Once your connection is complete, you can use the SQL code from the database-export map from the Github repo.
Making the Program Start Automatically
To make sure the app starts automatically when your raspberry pi boots, we have to make some small changes
- Create a file named 'SmartMailbox.service'
- Put the code at the end of the step in your file
- Change the location with the following command: sudo cp SmartMailbox.service /etc/systemd/system/SmartMailbox.service
- Test with the following command: 'sudo systemctl start SmartMailbox.service'
- To stop the test, enter: 'sudo systemctl stop SmartMailbox.service'
- To view the logs, type: 'journalctl -u SmartMailbox.service'
- If everything works, enable the service via the following command: 'systemctl enable SmartMailbox.service'
[Unit]
Description=ProjectOne Project
After=network.target
[Service]
ExecStart=/usr/bin/python3 -u /home/student/2021-2022-projectone-ClaeysKobe/backend/app.py
WorkingDirectory=/home/student/2021-2022-projectone-ClaeysKobe/backend
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
The End!
Congratulations, you're smart mailbox should now work perfectly!