Lytter - Smart Bin

by DaanDeWilde in Circuits > Raspberry Pi

170 Views, 1 Favorites, 0 Comments

Lytter - Smart Bin

Lytter.png

Trash is a daily aspect of our lives, you can't avoid it but that doesn't mean it should be a burden and you shouldn't keep track of it.

Lytter is a smart trashcan that keeps track of its trash generation and trash collections. That way, you'll have some insight on how much trash you really generate and maybe reduce it as much as possible. Because let's be honest, our planet could really use it.

Via the web dashboard, you'll be able to see each trashcan in detail and keep a close eye on your trash collection but you'll also be able to see when it's full and close or open the lid with an electromagnet.

Gather the Components

The first and maybe the easiest step is to gather all the components you need to build your very own smart trashcan. This project cost me about 190/200 euros, although this depends on what you already have and what you have to buy.

I will list the most important components here:

  • 1 x Raspberry Pi 4 Model B 4GB
  • 1 x Pi Breakout cable + cobbler kit
  • 1 x Contact switch (reed switch)
  • 1 x HC-SR04 ultrasonic sensor
  • 1 x Load cell (5-10Kg)
  • 1 x Load cell amp HX711
  • 1 x LCD display module
  • 1 x I2C PCF8574 chip
  • 1 x 12V electromagnet
  • 1 x 12V 4A power supply (Male 2.1mm barrel jack)
  • 1 x USB-A to USB-C cable (Make sure it can handle at least 2A)
  • 1 x 1.25-35V DC to DC buck converter module
  • 1 x Diode
  • 1 x TIP120 Mosfet (with heat spreader)
  • 1 x Potentiometer (10K Ohm)
  • 1 x push button
  • 1 x Female 2.1mm barrel jack terminal block
  • Some resistors (470, 1K, 2K, 2.2K Ohm)
  • Hinges
  • MDF wood 9mm thick
  • 23x25mm lumber

You can also find a PDF of my bill of materials (BOM) below for easy printing. In there you'll find all components listed above with some links to shops that sell them (In Belgium/EU). Together with a more detailed estimate of the pricing for each component.

Beyond these components, you'll probably need some extras like:

  • Breadboards
  • An SD/Micro SD card for the operating system of your Raspberry Pi
  • Cables
  • A soldering iron
  • Optional prototype boards instead of breadboards
  • PCB standoffs to mount everything on the wood
  • Heat shrink to tie everything together.

And maybe some other small things that you want to add or do differently than I do.

Connecting Your Components

Fritzing breadboard.png
Fritzing elektronica_schema.png
IMG_8861.jpg
IMG_8852.jpg
IMG_8854.jpg
IMG_8865.jpg
IMG_8876.jpg

Once everything has arrived, it's time to connect your components to each other. Make sure to test each component when it arrives to make sure you have working components.

As you can see, I have included the electrics diagram and the Fritzing breadboard diagram with the pictures. You can find those exact diagrams below as PDFs for easy printing.

Some tips for connecting your components:

1) Build everything on breadboards while setting up the Pi, database, website, ... for easy troubleshooting.

2) I would recommend building in steps:

- first the Raspberry Pi with simple sensors like the ultrasonic sensor, reed switch, buttons, weight sensor.

- Then the LCD with the PCF and potentiometer.

- Then the electromagnet with the TIP120.

- And last the power delivery so you can test the rest with a power module that you can plug into your breadboard. If you don't have one of those you can start with this step but make sure to divide your 12V, 5V, and 3.3V rails carefully. The output of your 12V-5V DC-DC converter should NOT be more than 5.1V.

3) I put a switch between my 12V power supply and the rest of the circuit to have a little more control at this point.

4) You could power your Raspberry Pi through the GPIO pins but I bought a cheap USB-A to USB-C cable, cut off the USB-A end, and connected the red and black (5V and GND) to my 12V-5V DC-DC converter. This way I could power my Pi safely without an extra power adapter. (The GPIO pins don't have power regulation or fuse protection like the USB-C interface has.)

5) You can connect your sensors to the GPIO pins that fit you the best, just make sure the SDA and SCL from the PCF are connected to the I2C SDA and SCL on your Pi. The rest shouldn't matter since there is an easy config file provided with the code where you can adjust the pins to fit your circuit.

Setting Up the Raspberry Pi

Now, it's time to set up your very own Raspberry Pi.

We are going to work on the Raspberry Pi OS.

To get everything working you'll need to install and configure:

  • Apache 2
  • MariaDB
  • Python 3
  • Git
  • Activate I2C
  • Give WiFi access

I am aware that this step can be a bit complicated so I provided an ready to go image file.

You can find the .img file in this google drive folder. Once you have downloaded this .img file, you can write it to a micro SD card and insert it into your Pi. Everything should boot and be set up correctly.

You can log in with the user:

Student

and the password (this is also the sudo password):

W8w00rd


Once the Pi is running you can give it access to your WiFi using the following command:

wpa_passphrase your_SSID your_password >> /etc/wpa_supplicant/wpa_supplicant.conf

sudo systemctl reboot hdcpcd.service

Then check if you have WiFi access with:

ping 8.8.8.8

The only thing you need to do now is log in to your GitHub account using the following commands:

git config --global user.name "Your name here"
git config --global user.email "your_email@example.com"

Setting Up the Database

Lytterdb ERD.PNG
Trashcan table.PNG
Device table.PNG
History table.PNG

Once your Pi is set up and you have a good connection with your home network and your Pi. You need to install MySQL workbench on your personal desktop to make your database. The download can be found here. and a setup/installation guide can be found here.

Once MySQL workbench is installed, you can make a new connection with the following credentials:

  • Connection Method: Standard TCP/IP over SSH
  • SSH Hostname: 192.168.168.168
  • SSH Username: student
  • SSH Password: W8w00rd
  • MySQL Hostname: 127.0.0.1
  • MySQL Server Port: 3306
  • Username: student
  • Password: W8w00rd

Once this is done, you will be able to connect to the database on your Raspberry Pi.

Then you can start making the database, I have included the ERD and screenshots from each table as pictures above. I have also included the SQL script to create the database below. You should be able to copy and paste the script and execute it to create the database.

Downloads

Cloning the Github Repository

IMG_6300.jpg
Home page.PNG
Details page.PNG
edit page.PNG
add page.PNG

Once your database is made you can clone my GitHub repository for the code.

I would recommend using Visual Studio Code and installing the 'Remote SSH' plugin to connect to your Raspberry Pi. That way you can easily clone my repository and edit everything you need straight from your own desktop.

My GitHub repository can be found here.

In the 'Code' folder you will be able to find:

  • All backend and sensor code in the 'Backend' folder.
  • My database export, a list of MySQL querry's I made for this project, and a Postman file to test your API in the 'Database export' folder.
  • All frontend code in the 'Frontend' folder.

Once the repository is cloned you can adjust the 'appconfig.txt' file in the 'Backend' folder to match the GPIO pins you used for each sensor together with the IDs you gave each sensor in your database.

If you just want to start with testing your circuit, you can use the 'sensor_code.py' file in the 'Backend' folder.

Please don't forget to edit the 'appconfig.txt' file.


At this point, your test setup should work as a functioning smart trashcan when you run the 'app.py' file in the 'Backend' folder. An IP should appear on your LCD screen, you can put this into google and it should direct you to the web interface.

It's also possible to create a service of the app.py file (a service will automatically start when the Pi starts and stop when the Pi shuts down). I have added a 'lytter.service' template file in the 'Code' Folder. You just have to add the path to the 'app.py' file, the 'Backend' folder, and fill in the username you chose while setting up your Raspberry Pi.

When that is done, you will be able to execute this command:

sudo cp lytter.service /etc/systemd/system/lytter.service

After doing this you will be able to stop and run the 'app.py' file with the following commands:

sudo systemctl start mijnproject.service

sudo systemctl start mijnproject.service

To make it run and stop when the Pi starts up / shuts down, execute the following command:

sudo systemctl enable lytter.service

Making the Housing

Lytter housing.png
IMG_6338.jpg
IMG_6343.jpg
IMG_6361.jpg
IMG_6374.jpg
IMG_6378.jpg
IMG_6384.jpg
IMG_6406.jpg
IMG_6503.jpg
IMG_6419.jpg
IMG_6434.jpg
IMG_6435.jpg
IMG_6441.jpg
IMG_6547.jpg

To make the housing you'll probably need some tools. I used a table saw, electric drill, a jigsaw, a nailgun, wood glue, nails, and screws. The table saw and nailgun aren't necessary, you can use a circular saw/jigsaw and a hammer instead.

I used a 9mm thick MDF wood panel and some lumber that's 35X25mm.

I would recommend splitting the build into 3 main components:

  • The body (A1, B1, C1, D1)
  • The lid (A2, B2, C2, D2, E)
  • The electronics platform with the bottom of the trashcan (F, G)

To start, you need to cut everything into the right dimensions:

  • 2x 350x450mm (D1, C1)
  • 2x 350x250mm (D2, C2)
  • 2x 282x450mm (A1, B1)
  • 2x 282x250mm (A2, B2)
  • 2x 282x332mm (E, G)
  • 1x 270x320mm (F)
  • 1x 180x131mm (flap of the trashcan)

Then you can cut your lumber into smaller pieces:

  • 4x 300mm
  • 4x 231mm
  • 4x 100mm

THE BODY

Once you have cut everything we can start building the body, You can start mounting your lumber (300mm) onto pieces A1 and B1 150mm from the bottom and flush with the top. Once they are on you can start nailing pieces C1 and D1 to them.

(Reference pictures 1, 2, 3, and 4)

THE LID

You can set the body to the side for a while. At this point, it would be best to start cutting your holes for the LCD display and the flap of the trashcan in piece D2. The hole for the flap should be slightly larger than the flap itself (180x131mm) since it should be able to move freely. Above the hole of the flap, I cut a smaller hole to fit my LCD with a jigsaw.

Once the right holes are in, you can mount the lumber (231mm) onto pieces A2 and B2, they should be placed flush with the bottom, 9mm from the top, and 9mm from the sides. When your lumber pieces are on, you can mount the flap to piece D2 with a hinge and put all pieces A2, B2, C2, D2 together and close it off from the top with piece E. Since you put your lumber 9mm down, piece E should sit flush on top.

(Reference pictures 5, 6, 7, and 8)

THE ELECTRONICS COMPARTMENT

Now you can start working on the electronics compartment. You can start by mounting your load cell to piece G. When this is done you can mount the rest of your lumber (100mm) underneath piece G, they should sit flush with all corners. Once your lumber is on, you can mount the final part, piece F to the other end of your load cell.

(Reference pictures 9, 10, 11, and 12)

When all 3 components are done, you can mount the lid to the body with some hinges. This is probably the best time to start painting all pieces, I waited until all electronics are in but that means you'll have to disassemble some bits to paint. Once your paint is dry and the lid is attached to the body, you're 90% done. I would recommend leaving the electronics compartment and piece E out for a bit so you can easily install all electronics and slide the electronics compartment in the body from below when everything is hooked up.

Installing the Hardware Into the Housing

Elektronica in behuizing.PNG
IMG_6500.jpg
IMG_6513.jpg
IMG_6527.jpg
IMG_6520.jpg
IMG_6522.jpg

Once your housing is done you can start putting everything in, this step takes some planning in advance, and just laying everything out can be a good idea.

In the first picture, you can see what component needs to go where. I labeled each component:

  1. The reed switch/contact sensor
  2. Electromagnet
  3. LCD screen
  4. Ultrasonic sensor (witch should do to the back of piece E and not the front)
  5. Weight sensor/load cell
  6. The place where your Pi should be mounted. The rest of the electronics can be mounted to piece G too.

This is where the recommendation of not sliding the electronics compartment in yet should make sense. This way you can easily mount everything in the body and the lid and route all the wires down while you mount the rest of the circuit to the bottom of piece G. Once everything is in place, you can slide the electronics compartment in and connect the reed switch, electromagnet, LCD screen, and ultrasonic sensor. I also made a small hole in pieces F and G to rout the wires.

Some tips:

1) If you have inconsistent readings from your ultrasonic sensor, try some sound dampening foam on the walls.

2) Try 'hanging' your ultrasonic sensor of the top piece to improve readings.

3) Label your cables so you always know what cable goes where.

4) Don't forget to make some holes in the back for the power supply and the button.

5) I used a cable raceway to guide all cables from the top to the bottom of the trashcan.

Enjoy Your Lytter Trashcan!

IMG_8882.jpg

At this point, your database should be working, the housing is built, the electronics are integrated into the housing.

If you chose to wait with painting the housing until now, you'll have to detach the LCD screen, the hinges, button, and female barrel plug. I decided to make the flap of the trashcan from aluminum so I chose not to paint that part but if you made it out of MDF like described in the instructions you can paint it as well.

Once your trashcan is painted or you're done integrating all the electronics your very own Lytter trashcan should be done!

The only thing left to do is test it. Thanks to the service we made earlier, you should be able to just plug your power supply in and everything should start running. An IP should appear on the LCD screen, you can surf to it on Google to visit the interactive dashboard.