Arduino – Automatic Fish Feeder
From the previous Arduino - Servo post, we've already learned how to run Servo motor with Arduino.
if not, just click the following button and take a look at the post to see what you can do. 🙂
Once you're ready to go further with Servo motor, now we can start. 🙂
From this post, we're going to make 'Automatic Fish Feeder' using Arduino and Servo.
Are you already excited? Let's dive in!
Please see the following diagram carefully and make your own system just like it!
Let's take a look at Software side.
If anyone does not know 'How to upload our sketch to Arduino', then please click the following article before you go.
Once your Arduino is ready, just type the following codes into your Arduino IDE.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
// 1 second : 1000;
// 1 min : 60000;
// 1 hour : 3600000;
// 6 hours : 21600000;
// 8 hours : 28800000;
// 10 hours : 36000000;
long FISHFEEDER = 28800000;
long endtime;
long now;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
now = millis();
endtime = now + FISHFEEDER;
while(now < endtime) {
now = millis();
}
//myservo.attach(9);
//delay(15);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
myservo.write(90);
// myservo.detach();
// delay(15);
// myservo.detach();
// delay(15);
}
So now you'll be able to see Servo motor only rotates with the factor your time-interval(FISHFEEDER) configured.
If you're not sure it's working or want to check it's working quickly, just change 'FISHFEEDER' to shorter time such as 5000 (5 seconds).
How was it? Have you had lots of fun or already got some better idea to extend this to your own project?
then go for it. 🙂
NP! orkney. I’m a little bit lazy these days, but there are lots of posts under progress yet.
I’ll keep updates. Thanks!