UNIHIKER K10 Lesson 9: Create an Automatic Cat Feeder with Cat Face Detection

Want to teach AI and coding in a fun, hands-on way? This cat face detection project using the UNIHIKER K10 is perfect for STEM educators, homeschool parents, and tech enthusiasts. Students will learn computer vision, IoT automation, and Python programming while building an automatic cat feeder—all aligned with CSTA, UK National Curriculum, and AP Computer Science standards.

Objectives

Using the cat face detection feature of the UNIHIKER K10, design a cat feeder that can automatically dispense cat food when the cat approaches eating.

Knowledge Goals

1. Master the method of cat face detection with the UNIHIKER K10.

2. Master the program for creating a cat feeder machine using the UNIHIKER K10.

Materials List

Hardware List:

HARDWARE LIST
2 UNIHIKER K10
2 USB 3.0 to Type-C Cable

Software: Mind+ Graphical Programming Software (Minimum Version Requirement: V1.8.1 RC1.0)

Basic Mind+ Software Usage

1. Open Mind+ and switch to offline mode.

2. Load UNIHIKER K10

Based on the previous steps, then click on "Extensions" find the "UNIHIKER K10" module under the "Board" and click to add it. After clicking "Back" you can find the UNIHIKER K10 in the "Command Area" and complete the loading of UNIHIKER K10.

3. Connect UNIHIKER K10

First of all, you need to use a USB cable to connect the UNIHIKER K10 to the computer.

Then, after clicking Connect Device, click COM7-UNIHIKER K10 to connect.

Note: The device name of different UNIHIKER K10 may vary, but all end with K10.

On Windows 10/11, the UNIHIKER K10 is driver-free. However, for Windows 7, manual driver installation is required: https://www.unihiker.com/wiki/K10/faq/#high-frequency-problem

Hands-on practice

Let’s start working on today’s course tasks. We will begin by building the cat feeder machine and gradually learn how to design an automatic cat feeder using the UNIHIKER K10.

Task 1: Build the cat feeder machine

In this part, we will first initialize the camera, add the food bowl, and build the cat feeder machine.

Task 2: Automatic feeding when the cat approaches

In this part, we will implement automatic feeding when the cat approaches.

Task 3: Set sleep mode to avoid repeated feeding

In this part, we will set the sleep mode for the feeder to avoid repeated feeding when the cat raises its head during feeding.

Task 1: Build the cat feeder machine

1. Hardware Setup

Insert the TF card into the card slot of the UNIHIKER K10, and confirm that the UNIHIKER K10 is connected to the computer using a USB cable.

2. Software Preparation

Make sure that Mind+ is open, the preset code appears in Python graphical mode, and the UNIHIKER K10 is successfully loaded. You can now start writing the project program.

3. Write the program

STEP1: Call the cat and dog detection command

We need to first use the "enable camera show" command to show the camera feed on the UNIHIKER K10 screen.

After turning on the camera, we find the "switch mode cat/dog detection"command and switch the camera to cat and dog detection mode.

STEP2: Add a Cat Bowl

The cat feeding machine requires a cat bowl to hold the cat food. Here, we use the "cache TF card image" command to display the cat bowl on the screen of the UNIHIKER K10. The command is as follows.

4. Program Execution

STEP1: Check and ensure the UNIHIKER K10 is connected to Mind+. Make sure the IP address is displayed in the "Menu Bar" section, indicating that the connection is established.

STEP2: Click the “Upload” button in the upper-right corner of the interface.

STEP3: Program Execution. When you run the program, the K10 screen will display the camera feed along with the empty cat bowl. When a cat face is detected, a green recognition box will appear around the cat face.

Task 2: Automatic Feeding When the Cat Approaches

In the previous task, we completed the setup of the cat feeding machine. Now, we need to implement the feature where the machine automatically dispenses cat food when the cat approaches and starts eating.

1. Write the program

STEP1: Detecting the Cat’s Proximity

How do we determine if the cat is close to the feeding machine? In our previous lessons, we learned about the concept of “close objects appearing larger, and distant objects smaller.” Similarly, the closer the cat is to the feeding machine, the larger its face will appear. As shown in the image below.

In the UNIHIKER K10, you can use the "detect cat/dog face?" command to check if there is a cat. When a cat is detected, you need to use the "get cat/dog face attributes length" command to obtain the length of the cat’s face. Set a critical value of 180 for the cat’s face length. If the cat’s face is larger than this value, it indicates that the cat is close to the feeding machine and wants to eat.

The related program commands are as follows:

STEP2: Set up the cat food feeding command

First, display "Feeding" on the UNIHIKER K10 screen to indicate that the feeding machine is in feeding mode. Then, use the "play TF card audio in background" command to play the sound of pouring cat food. At the same time, making the cat bowl gradually change from empty to half-full to full, simulating the process of the bowl filling with food. The related program commands are as follows.

2. Program Execution

STEP1: Connect the UNIHIKER K10.

STEP2: Click the “Upload” button in the top right corner of the interface.

STEP3: When the cat approaches the feeding machine, it will automatically feed the cat food and display the current status of the feeding machine on the screen.

Task 3: Set Sleep Mode to Avoid Repeated Feeding

In Task 2, the feeding machine was continuously dispensing food. In real life, once the bowl is filled with cat food, the cat lowers its head to eat, occasionally looking up. To prevent the machine from detecting the cat’s face repeatedly and dispensing food again, we need to set a sleep mode for the feeding machine.

1. Write the Program

When the cat lowers its head to eat the food, we will set a sleep period (5 seconds) to allow the cat to finish eating. During these 5 seconds, the feeding machine will be in a sleep state. We will use a variable "Sleep Time" to track the sleep duration. Once the sleep time ends, and the cat lifts its head after finishing the food, the feeding machine will detect the cat’s face and automatically dispense more food. Here’s the process.

We need to set the initial value of the "Sleep Time" to 0. After the feeding machine dispenses food, if the cat’s face length is less than 100, the “Sleep Time” will be set to 5, initiating the sleep countdown.

When the sleep state is activated, the screen of the K10 will display a countdown of the remaining sleep time. Once the sleep time ends, simulating that the cat has finished eating, the bowl will be switched back to an empty state.

The complete program instructions are as follows.

2. Program Execution

Click "Upload" and after the feeder dispenses cat food, the cat will start eating, and the feeder will enter sleep mode to avoid dispensing food repeatedly. Once the sleep time ends and the cat is detected again, the feeder will automatically dispense more food.

Knowledge Hub

1. Cat and Dog Detection Command

2. Cat and Dog Keypoint Detection

Ready to bring this purr-fect project to life? Download our code samples and start now. Perfect for educators, makers, and pet lovers.

[Get UNIHIKER K10 here]

Want to keep learning? Continue your learning journey with our other lessons.

Lesson1: Build a Light-Responsive Virtual Pet Dog

Lesson2: Design a Whack-a-Mole Arcade Game

Lesson3: Build Portable Walkman-Style Music Player (KS3/CSTA/DigComp)

Lesson4: Design Smart RFID Unmanned Supermarket

Lesson5: Build IoT Smart Greenhouse Monitoring System

Lesson6: Build a Voice-Controlled Smart Home Assistant

Lesson7: Build a Face Recognition AI Camera for Christmas Projects

Lesson8: Create an AI-Powered Campus Gatekeeper with Facial Recognition

icon 【Image】Lesson 9.zip 260KB Download(2)
icon 【Code】Lesson 9-K10 Cat Face Detection- Cat Feeder.mp.zip 167KB Download(1)
icon 【PDF】UNIHIKER K10 Lesson 9.pdf.zip 1.36MB Download(1)
License
All Rights
Reserved
licensBg
0