X
Home > Blog > STEM for Arduino > HOW to Build an Automatic Feeding System with KidsIOT

HOW to Build an Automatic Feeding System with KidsIOT

By r August 28th, 2024 459 views
1. Description
The automatic feeding system is composed of a kidsIOT main board, an ultrasonic sensor and a servo. The ultrasonic sensor is used to detect the distance of pets in the feeding area. When the pet approaches the food bowl, the sensor detects that the distance is getting closer. After triggering the signal, it controls the servo to open the feed box and automatically feed the animals.

2. Components

Img

Img

Img

Img

kidsIOT Mainboard×1

Ultrasonic Adapter Board×1

Ultrasonic Sensor×1

Servo×1

Img

Img

Img

Wire×1

USB Cable×1

Automatic Feeding System LEGO Pieces×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Process 6:

Img

Process 7:

Img

Process 8:

Img

Process 9:

Img

Process 10:

Img

Process 11:

Img

Process 12:

Img

Process 13:

Img

Process 14:

Img

Process 15:

Img

Process 16:Initialize the servo angle

Wiring of servo Img

First write the following code in KidsBlock software and upload the code to the kidsIOT mainboard, then the servo will rotate 190° . (Note: If the servo can not rotate, you can press the RESET button on the kidsIOT board.)

Img

Process 17:

Img

Process 18:

Img

Process 19:

(Note: Do not twist the servo)

Img

Process 20:

Img

Process 21:

Img

Complete

Img

4. Wiring Diagram

Module

kidsIOT Mainboard

Ultrasonic Adapter Board

No.9 port(Trig–io18,Echo–io19)

Servo

G/V/io33 port(Brown→G,Red→V,Orange→io33)


Ultrasonic Sensor

Ultrasonic Adapter Board

Vcc

VCC

Trig

Trig

Echo

Echo

Gnd

GND

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Servo rotation

Img

(1). Programming Steps
Step 1:Description of the Building Block

Img

Set the servo’s channel and output (rotation) angle to the specified PWM pin.

Step 2:Write the Program

① Set the pin IO33 (control pinio33) connected to the servo to “Output” mode.

Img

② Initialize the control channel of the servo to CH2 (LT1) and the initial angle to 190°, with a delay of 0.5 seconds.

Img

③ The servo rotates from 190° to 120° and then to 60° every 0.5 seconds.

Img

④ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard, then power up via the USB cable, then servo will rotate.

6. Read the Value of Ultrasonic Sensor

Img

(1). Programming Steps
Step 1:Add the Ultrasonic Sensor

Tap the “Sensor” module in the “Extension” , then select “Ultrasonic Sensor” and click Imgto return to the programming interface.

Img

Img

Img

Step 2:Description of the Building Block

Img

This block is used to measure distance to the specified pin, and the distance unit can be cm or inch.

Step 3:Write the Program

① Set the baud rate to 15200.

Img

② Set the Trig pin of the ultrasonic sensor IO18 to “output” mode, and the Echo pin IO19 to “input” mode.

Img

③ Set Trig to IO18 and Echo to IO19, and the serial port prints the distance value detected by the ultrasonic sensor at 0.1 second intervals.

Img

④ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. Move your hand in front of the ultrasonic sensor. When you are close to it, the displayed distance value becomes smaller. When you move away from it, the value becomes larger.

Img

7. Automatic Feeding System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Programming Steps

① Set the baud rate to 15200, the Trig pin of the ultrasonic sensor IO18 to “output” mode, and the Echo pin IO19 to “input” mode.

Img

② Set the pin IO33 connected to the servo to “Output” mode, initialize the control channel of the servo to CH2 (LT1) and the initial angle to 190°, delay 0.5 seconds.

Img

③ Define a “Distance” global variable to store the distance value detected by the ultrasonic sensor.

Img

④ Set the Trig pin and Echo pin of the ultrasonic sensor, and print the read distance value of the ultrasonic sensor on the serial port.

Img

⑤ Determine the distance detected by the ultrasonic sensor. If 2cm < distance value < 7cm, the feed box will be opened; otherwise, it will be closed.

Img

⑥ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. If an animal is detected within 2cm-9cm, the feed box will be opened to feed the animal.

Img

8. Common Problems

Q1: Why doesn’t the servo work?

A: It may be stuck. Before assembling the servo, use the code to adjust it to 80°.

Q2: Why is the detection distance inaccurate when using the ultrasonic sensor?

A: Measurement should be started from the transmitting head of the ultrasonic sensor. This module is not a high-precision ultrasonic distance detection module and may exist errors.

Img

HOW to Build A Light Controlled System with KidsIOT
Previous
HOW to Build A Light Controlled System with KidsIOT
Read More
How to Program Relay Module on Kidsuno
Next
How to Program Relay Module on Kidsuno
Read More
Message Us