Skip to content

My raspberry-pi powered, motion sensing, AI-trained, cat-detecting, publisher/subscriber broker (MQTT), app-enabled cat feeder.

License

Notifications You must be signed in to change notification settings

thecheebo/Smart-Cat-Feeder

Repository files navigation

Smart Cat Feeder

This is a walkthrough of a raspberry-pi powered, motion sensing, AI-trained, cat-detecting, publisher/subscriber broker (MQTT), app-enabled cat feeder I built for my cat Basil (pictured below).

Basil

Basil

A 1.5 minute demonstration of Basil and I using it. Here is a link of me using it. This solo project was completed for CS 498 Internet of Things during my Fall 2020 semester at University of Illinois Urbana-Champaign.

Table of Contents

Materials
Installation
Motion Sensing
Google's Object Detection API
Servo's
Usage
Credits
License

Materials

Sparks flying

Warning Sparks flying while cutting metal. Please be sure to wear eye Protection

Installation

  1. Get both your pringles can and soup can and remove the paper wrapping from the soup can. You can use wrapping paper on your pringles to make it look nicer at the end but thats optional.
  2. Cans

  3. Get a sharpie and mark the bottom of both cans like this:
  4. Soup Can Pringles Can

  5. Get out a .5 inch spade bit from your drill bit set, and WEAR YOUR EYE PROTECTION
  6. .5 inch spade bit

  7. It should look like this afterwards
  8. Can with hole in it

  9. Time to break out the dremel. Keep your eye pro on. If you havnt used it before, watch some youtube videos please. Here is a link of me using it.
  10. Dremel

  11. Make sure to cut a hole in the back for the raspberry pi power cable, 4 holes for the servo, and an opening for the food to dispense. Insert zip ties to attach MG995 servo.
  12. Can Can Can Can

  13. This step is optional but I wrapped my can with cute kitty wrapping paper, although dont get one that is glittery like my wife bought for me.
  14. Can Can

  15. We'll come back to installing the pi/camera/motion sensor/servo after you've tested it all out.

Motion

The purpose of the motion sensor is to activate the object detection algorithm. It's compute heavy and activates the camera. We don't want to always be running the camera, so a more low-powered approach is using a simple motion sensor for when Basil (cat) walks in front of the cat feeder, and only then it will start the object detection api.

Attach your motion sensor like this:
image

Here is a good tutorial if you are having difficulty but it is pretty self exaplanatory. https://projects.raspberrypi.org/en/projects/parent-detector/1

Installed in the back

This is the camera and the sensor in the back.

Installed in the front

Here is the sensor on the top and the camera in the middle.

Dectection

Install the rapberry camera pi. There are a few tutorials on how to do so, so there is no need to repeat their great work: https://projects.raspberrypi.org/en/projects/getting-started-with-picamera https://thepihut.com/blogs/raspberry-pi-tutorials/16021420-how-to-install-use-the-raspberry-pi-camera

After you have installed the camera and tests that it has worked. Please check out TensorFlow's object detection API that was designed and specialized for Raspberry Pi. The AI model has been trained to detect 100 or so items. You can check out the list and instructions on the link.

https://github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi

When you have finished the guide take a look at tf_image_dection.py file which includes the following code:

 for detected_obj_data in results:
              if detected_obj_data["label"] in ['cat']:
                print (detected_obj_data["label"], "has been detected")
                return True

When motion is sensed, and activates the object detection, it will put into a list, from the detect_objects method.

def detect_objects(interpreter, image, threshold, labels):
  """Returns a list of detection results, each a dictionary of object info."""
  set_input_tensor(interpreter, image)
  interpreter.invoke()

Servo

If you have never worked with servos, then it is a good time to read a guide or two on how to control servo motors on the raspberry pi.

https://www.digikey.com/en/maker/blogs/2021/how-to-control-servo-motors-with-a-raspberry-pi

https://pypi.org/project/RPi.GPIO/

Here is the method to set the angle of the servo, which activates using the GPIO library.

pwm = GPIO.PWM(3, 50)

pwm.start(0)

def set_angle(angle):
    
    duty = angle / 18 + 2
    
    GPIO.output(3, True)
    pwm.ChangeDutyCycle(duty)
    sleep(1)
    GPIO.output(3, False)
    pwm.ChangeDutyCycle(0)

Once you have played/installed with your servo, you can attach it to the bottom of the soup can and either use a combination of zipties or super glue to attach it there.

servo

Then you can install the raspberry pi after you have connected the camera/motion detector/servo.

servo

Usage

Watch this introduction to the MQTT broker (pub/sub) platform.

https://www.youtube.com/watch?v=EIxdz-2rhLs

Credits

https://github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi

https://www.youtube.com/watch?v=dqr-AT5HvyM

License

MIT License

Copyright (c) 2021 Albert Yeh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

My raspberry-pi powered, motion sensing, AI-trained, cat-detecting, publisher/subscriber broker (MQTT), app-enabled cat feeder.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages