Case 06: Auto Pets Feeder
7. Case 06: Auto Pets Feeder#
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.
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.
7.5. Hardware Connection#
Connect the sonar:bit to P1, the servo to P2 on IoT:bit.
7.6. Software Program#
Click “Advanced” in the MakeCode drawer 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.
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.
Save the returned value of the ultrasonic sound sensor as the variable “ultrasonic_distance”.
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.
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.
If there is any pet detected by the ultrasonic sound sensor, the feeder opens its lip and give out the food to pets.