Simple Automatic Arduino Pet Feeder

Last Updated on March 16, 2024

Allow any Pet to eat as when they want by using this Simple Automatic Arduino Pet Feeder. This Project detects the pet near to the food bowl and allows desired quantity food to them. This Project uses Ultrasonic Sensor HC-SR04 distance sensor and Micro Servo SG90 motor, these are easily available elements.




For an example here we taken a small bowl and empty water bottle and covered bottle open with paperboard attached with the servo motor and placed Ultrasonic Distance Sensor in front of the water bottle, and programmed Arduino Uno board as if pet reach bowl with in 30 Cm then Servo motor opens paperboard knob and pour food on bowl then closes the bottle and wait for 50 Seconds, If the pet leaves then it remains closed or if the pet present with in 30 Cm then again servo motor paperboard knob allows food and closes the bottle.

Simple Automatic Arduino Pet Feeder Model Setup

Simple Automatic Arduino Pet Feeder Wiring

Simple Automatic Arduino Pet Feeder Schematic

Components Need

  1. Arduino Uno
  2. Servo motor SG90
  3. Ultrasonic Distance Sensor HC-SR04
  4. Connecting Wires & Battery as your need
  5. Model Setup as your Requirements

Simple Automatic Arduino Pet Feeder Code

Connect the sensor and Servo motor and check the operation after uploading the following Code and once works fine then Implement this setup as per your requirements.

/* Simple Arduino Pet Feeder using Ultrasonic Sensor
 *  By www.theorycircuit.com
 *  Arduino Uno board, ultrasonic sensor (HC-SR 04), micro servo sg90 
 */
#include <Servo.h>
#define trigPin 4
#define echoPin 5

int pos = 0;

Servo servo_9;

void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

int duration = pulseIn(echoPin, HIGH);

int distance = (duration/2) / 29.1;
  if (distance < 30)  //if pet reach food less than 30cm then servo motor will open knob
{
servo_9.attach(9, 500, 2500);
  // sweep the servo from 0 to 180 degrees in steps
  // of 1 degrees
  for (pos = 0; pos <= 180; pos += 1) {
    // tell servo to go to position in variable 'pos'
    servo_9.write(pos);
    // wait 15 ms for servo to reach the position
    delay(10); // Wait for 10 millisecond(s)
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    // tell servo to go to position in variable 'pos'
    servo_9.write(pos);
    // wait 15 ms for servo to reach the position
    delay(1); // Wait for 1 millisecond(s)
  }
 

}
else {

}
 delay(50000); // Wait for 50 Seconds
}




Leave a Reply

Your email address will not be published. Required fields are marked *