Smart Mailbox With Website

by KobeClaeys in Workshop > Home Improvement

178 Views, 1 Favorites, 0 Comments

Smart Mailbox With Website

IMG_8114.JPEG

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)

Like this one

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

  1. To turn the Raspberry Pi on
  2. To turn the Raspberry Pi off
  3. To display the IP on the LCD
  4. 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.

Cutting the Basics

schema.png
IMG_7739.JPEG
IMG_7740.JPEG

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

IMG_7984.JPEG
IMG_7744.JPEG
IMG_7976.JPEG
IMG_7977.JPEG

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

IMG_7746.JPEG
IMG_7968.JPEG
IMG_7974.JPEG

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

IMG_7986.JPEG
IMG_7971.JPEG
IMG_7975.JPEG
IMG_7972.JPEG
IMG_7983.JPEG
IMG_7985.JPEG
IMG_7982.JPEG
IMG_7978.JPEG

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

IMG_8032.JPEG
42931717-827a-41ba-b04b-bb4bf8e72cd0 (1).jpg
IMG_8152.JPEG
IMG_8151.JPEG
IMG_8153.JPEG
IMG_8144.JPEG
IMG_8147.JPEG
IMG_8148.JPEG

Lasers + LDRs

  1. Drill 5 holes for the laser on the inner part (backside, picture 1) at around 36 cm starting from the bottom.
  2. Drill 5 holes for the LDRs on the other side.
  3. 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

  1. For your convenience: Put all female - male wires on the pins of your LCD and put them together with duct tape.
  2. Screw the LCD in place

Buttons

  1. 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).
  2. Put the cables in and glue the buttons into place.

RFID-Scanner

  1. 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).
  2. Screw the RFID-Scanner in place.

Magnet sensor

  1. Screw the wired part onto the side
  2. Screw the unwired part on the lid itself (make sure it is close enough to the wired part) (picture 7).

Led strip

  1. 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

  1. Download Raspberry Pi Imager (if you don't already have it of course)
  2. Install Raspberry Pi os on an SD card of at least 8 Gb
  3. Go to your Raspberry Pi's directory and open cmdline.txt
  4. Type 'ip=192.168.168.169'
  5. create a file 'ssh' without extensions
  6. Save the file, safely remove the sd-card and put your sd-card


Configuring your Pi

  1. Make your Pi ready
  2. Plug an ethernet cable in your Pi and pc
  3. Connect via putty (download here) with ip: 192.168.168.169
  4. login with default username / password (pi / raspberry)
  5. Type sudo raspi-config and press enter
  6. In the menu, select advanced (6) > Expand Filesystem (1)
  7. Reboot your Pi
  8. Add wifi access
  9. Type sudo -i and press enter
  10. Type wpa_passphrase


Installing the code

  1. We will use Visual Studio Code (download here)
  2. Install GitHub on Visual Studio Code (you can follow the official tutorial here)
  3. Download the code here (Github repo)

Setting Up the Database

ERD_database.png
Screenshot 2022-06-19 160235.png

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

  1. Choose Standard TCP/IP over SSH for Connection Method
  2. SSH Username: pi (unless you've changed it)
  3. SSH Password: raspberry (unless changed)
  4. Username: pi (unless changed)
  5. 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

  1. Create a file named 'SmartMailbox.service'
  2. Put the code at the end of the step in your file
  3. Change the location with the following command: sudo cp SmartMailbox.service /etc/systemd/system/SmartMailbox.service
  4. Test with the following command: 'sudo systemctl start SmartMailbox.service'
  5. To stop the test, enter: 'sudo systemctl stop SmartMailbox.service'
  6. To view the logs, type: 'journalctl -u SmartMailbox.service'
  7. 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!