The measurement of Trash can fill level can be done by multiple means such as measuring the distance between the lid and trash content level. Another possible measurement could be measuring the weight of the trash can via a load cell (weight sensor). However, due to the fact that trash contents could vary in nature (such as solid waste vs plastic or paper) measuring weight could not guarantee an accurate fill level. Therefore measuring empty space remains the most practical way to measure the fill contents. It also simplifies the design because all the circuitry could be contained in one place, i.e. the top of the trash can.
As an embedded system, we will use an emulated Raspberry Pi platform (based upon Raspberry Pi® 2 Model B+). To measure the trash fill level we will use the most popular HCSR04 Ultrasonic distance sensor. The user guide documentation of the sensor and functioning information can be found in the link given below.
This sensor requires two connections to the Raspberry Pi GPIO. One GPIO connection for the trigger and another GPIO connection for the echo.
The trigger can be considered a simple pulse that turns the sensor on, each time a distance is going to be measured. It should last 10 microseconds. The echo is the output signal. The length of the signal is proportional to the distance measured and is hence used to measure the actual distance. In our application, the trigger is connected to pin 5 (GPIO) and echo is connected to pin 6 (GPIO). Knowing that, the distance can be calculated by:
2*Distance=(Echo Duration)*(Ultrasonic Velocity)
Note that there is a 2 x-factor in the equation. This is because the formula is used to measure the total distance traveled by the ultrasonic waves, hence it accounts for both directions of travel.
Knowing that the ultrasonic velocity is of X m/s, the Distance can be calculated as:
Distance = (Echo Duration)*17150