Case 03: Smart Trash Can
Most of the trash cans sit on the roadside are designed by throwing in the trash from the side part without lids, the bad smell are easily to get especially in hot summer days, and there are some cans with lids but require us to open it by hands, which may easily get virus and dirt attached to our body. Therefore, we could design a smart trash can to open the lids by itself while there are people appraching and close when they are leaving.
Detect if there are humans approaching with the sonar:bit, program to open the lid automatically when people come and to close when they leave.
Connect the sonar:bit to P1, the servo to P2 on IoT:bit.
Click "Advanced" in the MakeCode to see more choices.
For programming, we need to add a package: click "Extensions" at the bottom of the MakeCode drawer and search with "iot-environment-kit" in the dialogue box to download it.
For programming, we need to add a package: click "Extensions" at the bottom of the MakeCode drawer and search with "servo" in the dialogue box to download it.
Save the returned ultrasonic distance value as the variable “ultrasonic_distance”.
Detect if there are people near the trash cans through the sonar:bit(note the detection range is 4~400cm), if the object is not in this scope, the returned value would be 0, therefore, here we need to define both of the minum and maxium value.
If the varible value is in the scope, it means there are people approching the cans, program to turn on the servo and open the lid, or it closes.
- If there are people approching the cans, the lid would be opened automatically or it closes.