Hello guys in this tutorial we are going to make automatic fish feeder mechanism with timer by using Arduino. In every 12 hours it will feed the fish. We can set any time we want because we are using real time clock in this project. So lets get started.

For making this project you will need,

  1. Arduino,
  2. Servo motor,
  3. Real time clock (DS1302),
  4. Plastic bottle,
  5. Cardboard,
  6. Pen,
  7. Jumper Wires.

We are taking plastic bottle as a hopper.

plastic bottle as a hopper

We will cut the pen and drill a hole like this on one end. So that whenever it reciprocate it will bring some pellet to fish bowl.

hole in pen

and second end of pen is attached to servo motor.

Attach servo motor and pen

Connect the Arduino, servo motor and real time clock module.

Automatic Fish Feeder with arduino

Now it is testing time. I am uploading a testing code which will reciprocate servo every 600 millisecond. We can see it is working fine.

Download library for Real Time Clock library from Github  OR you can download it from here because github library may change by the time or it may not work.

Download Real time clock library DS1302.zip

Testing Code:
#include <Servo.h>
Servo myservo;

void setup() {
myservo.attach(9); 
}

void loop() {
myservo.write(0);
delay (300);
myservo.write(45);
delay (300);
}
Automatic Fish Feeder code:
#include <DS1302.h>
#include <Servo.h>
Time t;
Servo myservo;
int Hour;
int Min;
int Sec;
// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
myservo.attach(9); 
myservo.write(45); 
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9200);
// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(8, 59, 50); // Set the time to 12:00:00 (24hr format)
rtc.setDate(8, 25, 2019); // Set the date to August 25th, 2019
}

void loop()
{
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
Sec = t.sec;
// Serial.print(Hour);
// Serial.print(":");
// Serial.print(Min);
// Serial.print(":");
// Serial.println(Sec);

//set the time for fish feeding 
if ((Hour== 10 && Min== 0 && Sec== 2)||(Hour== 21 && Min== 0 && Sec== 2)) {
myservo.write(0);
delay (300);
myservo.write(45);
delay (300);}
}
Explanation:

Lets see the automatic feeder code. Add servo library and real time clock library.

#include <DS1302.h>
#include <Servo.h>

Initially servo motor will be at 45 degree angle. So that it will prevent pellet to drop into a fish bowl.

myservo.write(45);

Set the time and upload the code.

rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(8, 59, 50); // Set the time to 12:00:00 (24hr format)
rtc.setDate(8, 25, 2019); // Set the date to August 25th, 2019

After setting up time, Comment out this lines and again upload the code.

//rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(8, 59, 50); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(8, 25, 2019); // Set the date to August 25th, 2019

This function get the real time.

t = rtc.getTime();

We are storing current time in separate variable like hours, minutes and seconds.

Hour = t.hour;
Min = t.min;
Sec = t.sec;

I am feeding my fish two times, so here i have used two condition you can add one more, if you want three times.

if ((Hour== 10 && Min== 0 && Sec== 2)||(Hour== 21 && Min== 0 && Sec== 2)) {
myservo.write(0);
delay (300);
myservo.write(45);
delay (300);}
}

When time matches with this time, servo will rotate to zero degree from 45 degree. And then again back to 45 degree. It will reciprocate like this 2 times. You can increase number of times reciprocation by increasing seconds.

Seconds in IF condition = 2 seconds.

Total delay = 600 millisecond.

No. of Reciprocation = 2000/600 = 3.333

Here i am using 2 seconds. Practically it should reciprocate three times as we have total delay of 600 millisecond but it is reciprocating two times only. As delay function is not that accurate. Do some your own research on how much feed you want and how many reciprocation you will need, find which works best for you.

As time reaches to defined time. Servo rotate and feed the pellet to the bowl.

Automatic fish feeder using arduino

Till then keep learning keep making.