Automatic Dog (or cat) Treat Dispenser with Arduino | Science Project
Summary
TLDRThis video tutorial demonstrates how to construct an automatic dog treat dispenser using an Arduino. It can be programmed for timed treat release, sensor-based interaction, or button-press training. The dispenser operates by rotating pre-loaded treat compartments over a hole, allowing treats to slide down a ramp into a tray. The project uses a Servo motor and real-time clock, with potential for customization using various sensors. Viewers can find a detailed parts list and circuit diagram in the description for those interested in building this at home.
Takeaways
- 🛠️ The video demonstrates building an automatic dog treat dispenser using an Arduino, which can be programmed for various functions.
- ⏰ The dispenser uses a real-time clock to track time and can be set to dispense treats at specific times of the day.
- 🔧 The mechanical design includes a hopper with compartments that rotate over a hole, allowing treats to slide down a ramp into a tray.
- 📦 For practical use, the dispenser should be made of sturdy, washable materials or placed out of the pet's reach to avoid damage from slobber.
- 🔩 The circuit includes components like a potentiometer for the LCD screen, a reset button, and optional LED and buzzer for alerts.
- 📝 The Arduino code provided can be customized for different behaviors, such as dispensing treats at set times or responding to sensors.
- 🔍 Arduino's compatibility with various sensors allows for customization, such as motion detectors or magnet sensors for pet interaction.
- 🔑 The script includes a detailed explanation of the code, including the use of libraries, setting up the real-time clock, and the loop function for treat dispensing.
- 🔄 The servo motor is programmed to rotate the compartments in increments, ensuring smooth movement and treat delivery to the tray.
- 🔒 The code includes a safety feature that requires a button press to reset the dispenser after all treats have been dispensed.
- 🔗 Additional resources such as tutorials for different sensors and a parts list are available through links in the video description.
Q & A
What is the main purpose of the automatic dog treat dispenser project?
-The main purpose of the project is to build an automatic dog treat dispenser using an Arduino, which can be programmed to dispense treats at certain times of the day, react to sensors that detect the dog's presence, or even train the dog to push a button.
How does the treat dispensing mechanism work in the device?
-The treat dispensing mechanism works by preloading the food or treats into compartments in a hopper. A servo motor rotates the compartments one at a time, and as each compartment rotates, it goes over a hole allowing the treats to slide down a ramp into a tray at the front.
Why is the cardboard prototype not suitable for a real pet environment?
-The cardboard prototype is not suitable for a real pet environment because the slobber from the pet would quickly ruin the paper, making it unsuitable for direct use.
What are the alternatives if one wants to use the dispenser at home for their pet?
-The alternatives include placing the dispenser high on a counter or shelf where the pet can't reach it, allowing treats to drop below, or building a more robust and washable version of the dispenser.
What is the role of the potentiometer in the circuit?
-The potentiometer is used to adjust the contrast on the LCD screen, which is necessary if one wants a readout of time and instructions.
What are the additional components that could be used to enhance the dispenser's functionality?
-Additional components like a reset button, LED, and buzzer can be used to enhance functionality, such as alerting the pet with a sound when a treat has been dispensed.
How can the dispenser be customized to train or reward certain behaviors?
-The dispenser can be customized to train or reward certain behaviors by using a variety of sensors compatible with Arduino, such as motion detectors, distance sensors, or magnet sensors that can detect a magnetic tag on the pet's collar.
What is the significance of the real-time clock in the Arduino for this project?
-The real-time clock in the Arduino is significant as it keeps track of the time, allowing the device to dispense treats automatically at certain times of the day.
How can one modify the code to dispense treats at different times of the day?
-One can modify the code by changing the conditions in the if statement to match the desired times of day when the treats should be dispensed, using the hour, minute, and second variables.
What is the purpose of the angle increment variable in the code?
-The angle increment variable determines the angle by which the servo rotates with each step, which corresponds to the number of compartments in the hopper. It needs to be adjusted based on the number of compartments to ensure the servo rotates correctly.
How does the code handle the end of the treat dispensing cycle?
-The code handles the end of the treat dispensing cycle by resetting the servo to its initial position and displaying a 'press button to restart' message on the LCD screen, waiting for the user to press the button to start the next cycle.
Outlines
🤖 Building an Arduino-based Automatic Dog Treat Dispenser
This paragraph introduces a project to create an automatic dog treat dispenser using an Arduino. The device can be programmed to dispense treats at specific times, react to sensors that detect the dog's presence, or even be trained to respond to a button press by the dog. The mechanism involves a hopper with preloaded treats and a servo motor that rotates the compartments over a hole, allowing treats to slide down a ramp into a tray. The video demonstrates a prototype made of cardboard, which is not suitable for direct use by pets due to slobber damage, suggesting the need for sturdier, washable materials for a real-life application. The paragraph also mentions the possibility of receiving a notification to reset the dispenser after all treats have been dispensed.
🔧 Exploring the Mechanical Design and Circuitry of the Dispenser
The second paragraph delves into the mechanical design of the treat dispenser, describing the use of popsicle sticks glued at 45° angles to create compartments attached to a servo horn. It details the assembly of the cardboard structure, including the servo motor attached through a hole in the cardboard, and the use of cardstock for legs and ramp leading to the treat tray. The paragraph also discusses the circuitry involved, mentioning a potentiometer for LCD screen contrast adjustment, an LCD screen for time readout, and optional components like a reset button, LED, and buzzer. The Arduino is highlighted for its versatility with various sensors, allowing customization for different behaviors or presence detection methods. The paragraph concludes with an invitation to view a cleaner circuit diagram and parts list in the video description.
💻 Coding the Dispenser for Timed Treat Distribution
The final paragraph focuses on the coding aspect of the project, explaining the use of the Arduino Uno R4 Minima with a built-in real-time clock and the necessary libraries for the servo control and optional LCD display. It outlines the process of setting up the code with constant variables for pins and time units, and the setup function for pin modes and initializing the LCD and serial communication. The loop function is described, detailing how it checks for specific second intervals to rotate the servo and dispense treats, with adjustments possible for different times of day or sensor-based triggers. The paragraph also discusses the servo angle increment based on the number of compartments and the importance of slowing down the servo motion for smooth operation. Additional functions for LED flashing and buzzer sounding, as well as time retrieval and LCD updating, are mentioned, with the promise of more detailed instructions and example code available through provided links.
Mindmap
Keywords
💡Arduino
💡Servo motor
💡Real-time clock
💡Compartments
💡Ramp
💡Circuit diagram
💡Sensors
💡Customization
💡LCD screen
💡Code
💡Debounce
Highlights
The video demonstrates building an automatic dog treat dispenser using an Arduino.
The dispenser can be programmed to dispense treats at specific times or in response to sensors detecting the dog's presence.
The device uses a Servo motor to rotate compartments filled with treats over a hole, allowing treats to slide down a ramp into a tray.
A real-time clock is used to keep track of time for scheduled treat dispensing.
The prototype is made of cardboard and popsicle sticks, which is suitable for demonstration but not for actual pet use due to slobber.
For home use, the dispenser should be made of washable materials or placed out of the pet's reach.
The Arduino program can be customized to train or reward pets for specific behaviors using various sensors.
An LCD screen is used for displaying time and instructions, but it's optional if not needed.
A potentiometer is included to adjust the contrast on the LCD screen.
The circuit includes a reset button, LED, and buzzer, which can be used to alert the pet when a treat is dispensed.
The video provides an overview of the parts and their functions rather than individual connections.
Arduino's compatibility with a wide variety of sensors allows for customization of the treat dispenser for different behaviors.
The video includes a demonstration of the code for dispensing treats at certain times using the real-time clock.
The code includes libraries for the Servo and Liquid Crystal display, and uses variables for time tracking.
The setup function in the code initializes the pins, servo, and LCD display.
The loop function updates the LCD, checks the time, and controls the servo to dispense treats at specified intervals.
The code includes a mechanism to reset the dispenser after all treats have been dispensed.
Additional functions are provided to flash an LED and sound a buzzer, and to update the LCD screen with the current time.
Detailed instructions, parts list, and circuit diagram can be found in the video description for those interested in building the project.
Transcripts
in this video I'll show you how to build
an automatic dog treat dispenser using
an Arduino you can program it to
automatically dispense treats at certain
times of day react to sensors that
detect your dog's presence or even train
your dog to push a
button here's how the device works the
compartments in this Hopper up at the
top are preloaded with the food or
treats a Servo motor rotates the
compartments one at a time the Arduino
uses a real-time clock to keep track of
the time and for the sake of
demonstration in this video I have the
motor program to rotate once every 15
seconds although for a real project you
would probably space that out much
further throughout the day as each
compartment rotates it goes over this
hole in the cardboard so the treats can
slide down a ramp into a tray at the
front now obviously this whole thing is
just made out of paper so that works
well for a demonstration at a science
fair but it would not be good for your
pet to eat out of this directly because
the slobber would pretty quickly ruin
the paper so if you want to use this for
real at home you can either place it up
high on a counter or a shelf where your
pet can't reach it so it can drop the
treats down below or you would have to
build something out of sturdier more
washable
materials after it has rotated all of
the way and dispensed all of the treats
on the next cycle I will get a
notification to press the button to
reset at which point it will rotate back
to its original position and I can load
it up with treats for the next
day let's take a look at the mechanical
design if we pop the servo horn off the
motor you can see that I have made the
compartments just by gluing together
popsicle sticks at roughly 45° angles to
make four different compartments but of
course you could space them out
differently to make a different number
of compartments those are hot glued to
the servo horn which presses on to the
motor shaft here the servo motor itself
has the shaft sticking through a hole
cut in the cardboard but the motor is
glued to the underside of the cardboard
I've made legs to hold the platform up
just out of rolled up tubes of card
stock and also made this ramp out of
card stock and taped it on to come down
into the tray at the bottom again all of
that works as a demonstration or if you
are using this for humans for something
like to dispense medication or candy
that isn't going to get the paper messy
but you would not actually want to use a
paper tray for your pet to eat out of
you would either want to make this out
of washable material or again put it up
high where your pet can't get to it so
the treats drop down below
let's zoom in to take a look at the
circuit now this is kind of a messy busy
circuit on the breadboard here so it's
hard to see all of the connections in
this video but you can go to the link in
the description to get a much cleaner
version of the circuit diagram along
with a parts list if you would like to
build this yourself so here I'm just
going to go through an overview of the
parts and what they're for rather than
going through each individual connection
so we have a potentiometer that adjusts
the contrast on the LCD screen the LCD
screen is really only necessary if you
want a readout of a time and the
instructions like press a button to
reset you don't need the screen if you
don't care about that a lot of these
connections are for the screen going
over to the Arduino I have that reset
button and then I also have an LED and a
buzzer that were not used in my
demonstration but for example if you
wanted to sound a buzzer to alert your
pet that the treat has been dropped you
could use the buzzer as
well now I have this demonstration
program to dispense treats automatically
at certain times but the great thing
about using an Arduino is that they are
compatible with such a wide variety of
sensors so for example if you want to
train or reward certain Behavior this
lets you customize your treat dispenser
to do that automatically you can use
anything from a motion detector to a
distance sensor that will measure how
far your pet is in front of something to
a magnet sensor that can detect a
magnetic tag on their collar so there
are lots of different ways you can
detect your pets presence you could
teach them to touch something so pets
don't have fingers like humans it's a
little hard for them to push buttons on
a breadboard like this but you could buy
a larger button teach your pet to press
the button you could use a microphone to
detect sound there are tons and tons of
options for how you can customize this
project so rather than showing you all
of those different options in this video
what I'm going to do is switch over to
the computer and demonstrate the code
for dispensing the treats at certain
times but you can find tutorials for all
of these different sensors in our
Arduino tutorial playlist Linked In the
description of this video and you can
then customize the code to use a
different sensor if you want but for now
let's switch over to the computer and
take a look at the code for dispensing
the treats at certain times using the
real-time clock here's the code remember
that you can download it from the link
in the description and you may need to
modify it depending on the changes and
customizations you make to your treat
dispenser so going through this line by
line at the top here we include several
libraries you need the servo library to
control the servo you only need the
Liquid Crystal Library if you are going
to include that liquid crystal display
and I should note that I am using an
Arduino Uno R4 Minima here which has a
builtin realtime clock if you are using
a separate external realtime clock
module we have a tutorial for an
external module from Adafruit Linked In
the description of this video in our
playlist
then the code will be different the code
in this video is specific to the
internal RTC on the Arduino R4 Minima we
then create a Servo object that we are
going to refer to using the servo
Library I defined some constant
variables for the pins I have different
things connected to and some other
variables for keeping track of the angle
the state of the button if you use one
and some delays to slow the servo down
and debounce or wait if you are using
the button so you don't accidentally
detect multiple button presses if you
hold the button down I also have time
variables for keeping track of the
different units of time year month day
hour minutes and seconds that is
assuming you are using the realtime
clock again if you going to modify the
code to make the motor react to a sensor
instead then you don't need to keep
track of the time and you don't need to
worry about those there is some code
based on the LCD Library to tell the
display which pins you are using to
communicate with the Arduino again so
you only need this part if you are using
that liquid crystal display and then we
get into the setup function where I have
pin mode commands to set different pins
as inputs or outputs for example the
button is an input the LED and the
buzzer are outputs and we tell it which
pin the servo is attached to set the
initial angle for the servo and
initialize serial communication
which is always useful for
debugging we set up the size of the LCD
the number of columns and rows and then
here is code to initialize the time for
the real-time clock and again this code
is unique to the built-in real-time
clock on the Arduino Uno R4 Minima where
you have to manually set the time right
before you upload the code so there are
other third party modules that will
automatically get the time when you
compile and upload the code here you
need to to remember to change this each
time you upload if you want it to be
accurate but again if you were using a
different realtime clock module this
code will be
different in the loop function I call a
function that is going to update the LCD
screen I will show you that later we
print the angle of the servo to the
serial monitor that is useful for
debugging and then here is really the
key part of the program so here is where
I am detecting certain times so I have
an if statement that says if seconds
equals 0 or that's what this double
vertical bar here means seconds equal 15
or seconds equals 30 or seconds equals
45 so I this isn't necessarily the most
efficient way to do this I could have
divided by 15 and checked the remainder
or something but instead I just wrote
out all four possible conditions so I
going to rotate the servo once every 15
seconds and this condition is what you
would change either if you are using the
real time clock and you want to make
this happen at different times of day
for example if you want to detect 9:00
a.m. you could write 9 and that's the
double Amper standand here minutes
equals z and seconds equals z so you
probably don't want to give your pet
treats every 15 seconds you would want
to change this to maybe dispense meals
twice a day or something like that so
again this is just for purposes of
demonstration for what I'm doing in this
video you need to change this to the
times of of day you want to dispense the
treats or if you are not going to use
the real-time clock at all you are going
to use other sensors instead then you
would need to add your code up here to
read values from Those sensors and
change the condition in this if
statement to depend on those sensor
readings again I am not going to
demonstrate that in this video because
we have tutorials for many different
sensors Linked In Our playlist in the
description of this video so you can go
check out those videos to learn how to
use different
sensors so whatever this condition is
whether it's the realtime clock or
something else assuming that condition
is true then inside this if statement
we're going to set the new angle
variable equal to the current angle plus
the angle increment or then going to
check as long as that new angle is less
than
180° we are going to slowly increase the
servo angle to the new position using
this WOW Loop so if you just use a
single Servo right command to go to the
new angle the servo motion will be very
fast and jerky and that's probably not
good so instead we use a while loop to
just increase the angle 1° at a time and
include a short movement DeLay So that
lets us slow the servo down so we keep
going until the angle reaches the new
angle and we've moved the servo to the
next position but note that there is an
else statement here and that will detect
if the new angle is actually greater
than 180° then that means we can't
rotate any further and we are going to
reset to the initial position so we have
another while loop that does the same
thing except this time we are decreasing
the angle by 1° at a time until it
equals zero and again we have a delay in
there to slow the servo motion down so
it is not too jerky so again to recap
the code is going to Loop through here
and each time it detects one of these
times the seconds is 0 15 30 or 40 5
it's going to increase the angle by my
angle increment variable which I should
have mentioned if I scroll back up I
have set to 45° in this program because
I built a hopper with four compartments
but if you have more compartments you
could decrease this angle to move in
smaller increments or if you only have
two compartments for example you would
increase this to 90 because the servvo
has a range of 180° so if you build
something with a different number of
compartments you would need to adjust
this angle accordingly so I'm going to
Loop through each time I detect one of
these times I increase that angle and
then once I've gone through the full
180° range I'm going to reset back to
the initial position I have a weit for
button press built in here before it
will start again so we display a press
button to restart message on the screen
and then we have this single line wow
Loop where the code is just going to get
stuck in this Loop until I press the
buttons so digital read button pin
equals low will be true when the button
is not pressed so the code will just be
stuck in this W Loop that does nothing
but the moment I press that
button this statement will become false
because digital read button pin will
equal high so this statement will now be
false it will break out of the loop
clear the screen and keep going I then
have two more functions down here that
just help me keep the code in my Loop a
little cleaner one is an optional
function to flash the LED and sound the
buzzer when the motor moves so if you
want an audible alarm so you alert your
pet to the food being dispensed you
could use the buzzer for that so this is
a loop that just blinks the LED and the
buzzer on and off a certain number of
times you can call that function from up
here if you want to do it where the
inputs are the number of flashes and the
delay or duration of each Flash in
milliseconds but I have that commented
out because I didn't want to use it in
in this video I then also have a
function for getting the time and
updating the LCD screen so I'm not going
to go through this in too much detail
because we have separate tutorials about
the realtime clock and the LCD but I get
the time from the Clock Store the time
in these different variables that I
created earlier and then have a bunch of
LCD print commands first to print the
month day and year although you could
rearrange that for different date
formats and and then to print the time
in hour minutes seconds
format remember that for written
instructions for this project including
the parts list circuit diagram and
example code you can check out the link
in the video description for over a
thousand other projects in all areas of
Science and Engineering check out our
YouTube channel and our website
www.sciencebuddies.org
浏览更多相关视频
Arduino Solar Tracker | Science Project
Robotic Arm with Arduino - Save/Play/Export/Import Positions.
DIY Automatic Alcohol Dispenser ($3 No Arduino Needed)
Arduino Self-Driving Car Lesson 3: Controlling Motor Speed
CANGGIH!!! Cara buat Kunci pintu Pakai PASSWORD
شرح طريقة تحكم step motor من خلال الاردوينو Arduino
5.0 / 5 (0 votes)