12. Case 11: Smart Trash Can#

12.1. Introduction#


  • If the trash can has no lid, it is easy to emit peculiar smell and affect the surrounding environment, but if the lid is closed and requires to be opened manually, it is easy to cause secondary pollution. Thus, we can design a smart trash can that automatically opens the lid when someone approaches.

12.2. Function#


  • Detect if there are humans approaching with the PIR sensor, program to open the lid automatically when people come.

12.4. Picture#


../../_images/microbit-Smart-Health-Kit-case-01-02.png

12.5. Hardware Connection#


Connect the PIR sensor to P1 and the servo to P2 on sensor:bit.

../../_images/microbit-Smart-Health-Kit-case-01-03.png

12.6. Software Programming#


Click “Advanced” in the MakeCode to see more choices.

../../_images/microbit-Smart-Health-Kit-case-01-04.png

For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “smarthome” in the dialogue box to download it.

../../_images/microbit-Smart-Health-Kit-case-01-05.png

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.

../../_images/microbit-Smart-Health-Kit-case-01-06.png

Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

12.7. Program#


Judge the value of the variable “IR”, if yes, program to display a “√” and set the servo to drive to 0° to open the lid of the trash can; or to display a “×” and set the servo to drive to 180° to close the lid.

../../_images/microbit-Smart-Health-Kit-case-01-07.png

Link: https://makecode.microbit.org/_KuhhtHVds1EH

12.8. Result#


  • If there are people approching the cans, the lid would be opened automatically or it closes.