8. Case 06: Auto Pets Feeder#

8.1. Introduction#


  • A travelling plan is mostly made in holidays, it’s a good choice but it could be concerned if we get our pets stayed at home in that period, if we could make a foods feeder for the pets during our holidays, it would be much helpful.

8.2. Functions#


  • Detect if there is any pet in the front of the feeder through the ultrasonic sound sensor, if yes, program to open the lid of the feeder and add food automatically.

8.4. Picture#


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

8.5. Hardware Connection#


Connect the sonar:bit to P1, the servo to P2 on IoT:bit.

../../_images/microbit-Smart-City-Kit-case-03-03.png

8.6. Software Program#


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

../../_images/microbit-Smart-City-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 “iot-environment-kit” in the dialogue box to download it.

../../_images/microbit-Smart-City-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-City-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.

8.7. Program#


Save the returned value of the ultrasonic sound sensor as the variable “ultrasonic_distance”.

../../_images/microbit-Smart-City-Kit-case-06-07.png

Judge if there is any pet in the front of the feeder by the returned value of the ultrasonic sonic sensor, note the effective detection range is 4~400cm, if the pet(other objects) is not in this scope, the returned value would be 0, thus, we need to give the maxium and minum value for the threshold.

../../_images/microbit-Smart-City-Kit-case-06-08.png

If the returned value is in the threshold scope, it means there is a pet in the front of the feeder, thus, program to drive the servos and give the good; or program to drive the servos to close it.

../../_images/microbit-Smart-City-Kit-case-06-09.png

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

8.8. Result#


  • If there is any pet detected by the ultrasonic sound sensor, the feeder opens its lip and give out the food to pets.