Automatic pet feeding machine using Arduino
Today, we are going to make an automatic pet feeder based on Arduino development board, which can automatically provide food to your pet in time. This project uses a DS3231 RTC (Real Time Clock) module to set the time and date when the pet needs to be fed. So, according to your pet’s eating schedule, the device will automatically put down or fill the food.
In this project, we use a 1602 LCD module to display the time, which is obtained by using a DS3231 RTC module connected to an Arduino UNO. In addition, it uses a servo motor to rotate the container to provide food, and also provides a 4*4 matrix keypad to manually set the time to feed the pet. You can set the rotation angle and container opening time according to the amount of food you want to feed your pet. The amount of food may also vary slightly depending on whether your pet is a puppy, kitten or bird.
Required Materials
● Arduino UNO development board
● 4 * 4 matrix keyboard
● LCD display module 1602
● One button
● Servo motor
● Resistance
● Connecting wire
● Breadboard
Circuit Schematic
In this Arduino based pet feeder project, to get the time and date, we have used RTC (Real Time Clock) module. We have used 4*4 matrix keypad along with LCD module 1602 to manually set the feeding time of the pet. The servo motor rotates the container and drops the food as per the time set by the user. LCD is used to display the date and time.
3D printed pet feeder model
We designed the container of this Arduino pet feeder using a 3D printer. You can also print the same design by downloading the file from here . The material used to print this model is PLA. It consists of four parts as shown in the following figure:
Assemble the four components and connect the servo motor as shown in the following diagram:
Introduction to DS3231 RTC Module
DS3231 is a RTC (Real Time Clock) module. In most of the electronic projects, it is used to maintain the date and time. This module has its own button battery which can be used to maintain the date and time even if the main power is removed or the MCU hardware is reset. So once we set the date and time in this module, it will always maintain it. In our circuit, we use DS3231 to feed the pet according to the time set by the pet owner, just like an alarm clock. When the clock reaches the set time, it operates the servo motor to open the container door and the food falls into the pet food bowl.
NOTE: When you use this module for the first time, you must set the date and time.
Code and Description
The complete Arduino code for the Automatic Pet Feeder is given at the end of this chapter.
Arduino has default library files for using servo motors and LCD module 1602. But for using RTC module DS3231 and 4*4 matrix keyboard with Arduino, you have to download and install these libraries. The download links of these two libraries are as follows:
● DS3231 RTC (Real Time Clock) module library
● 4 * 4 matrix keyboard library
In the following code, we defined the libraries, “#include <DS3231.h>” for the RTC module, “#include <Servo.h>” for the servo motor, “#include <LiquidCrystal.h>” for the 16*2 LCD, and “#include <Keypad.h>” for the 4*4 matrix keypad.
In the following code, we have defined the keymap for the 4*4 matrix keypad and assigned the Arduino pins to the rows and columns of the keypad.
Here, we create the keyboard by using the following command in the code.
We assign A4 and A5 of Arduino board to connect SCL and SDA pins of DS3231. Also, assign pins to LCD and initialize servo motor.
In the following code, we declare t1 to t6, key and array r[6], and feed.
In the following code, we set up all the components for initialization. For example, in the code “servo_test.attach(10);” , the servo motor is connected to the 10th pin of the Arduino. A0, A1, and A2 are defined as output pins, and then the LCD and RTC modules are initialized.
Now, the important part to understand is how the loop function works. Whenever the button is pressed, it goes to level 1 which can be read by “buttonPress = digitalRead(A3)” . Now it goes into the ‘if’ statement and calls the ‘ setFeedingTime ‘ function. It then compares the real time with the time entered by the user. If the condition is true, i.e. the real time and the entered time are the same, then the servo motor rotates to 100 degrees and returns to its initial position after a 0.4 second delay.
In the void setFeedingTime() function code, after pressing the button, we can enter the feeding time of the pet and then we have to press ‘D’ to save the time. When the saved time matches the real time, the servo starts rotating.
How an automatic pet feeder works
After uploading the code to the Arduino Uno development board, the LCD module will display the corresponding time and date. When you press the button, it will ask the pet’s feeding time, and you have to enter the time using the 4*4 matrix keypad. The display will show the time entered, and pressing the ‘D’ key can save the time. When the real time and the input time are consistent, the servo motor rotates from the initial position 55⁰ to 100⁰ and returns to the initial position again after a delay. Since the servo motor is connected to the food container door, when it moves, the door opens and some food falls into the bowl or plate. After a delay of 0.4 seconds, the servo motor rotates again and closes the gate. The whole process is completed in a few seconds. This is how your pet automatically gets food at the time you enter.
You change the time and rotation angle according to the amount of food. If you have problems making similar projects, please reply under this post.
Code
The complete code used in this article is as follows: main.rar (1.21 KB, downloaded 476 times)