# Timed Fish Feeder
![[timed_fish_feeder.jpeg]]
## Overview
This was a simple [[Arduino]] project that has long since been salvaged for parts, but when it was operational, it would dispense a small amount of fish food at certain intervals over time. If I'm interpreting the code right, I needed to power on the Arduino at the right time so that the clock would make sense, and then the `loop()` logic would simply run once per day.
It was super janky by any standard, as the mechanism was literally a piece of cardboard with fish food on it. An electric motor with a gear on the end of the shaft would spin, vibrating the cardboard's surface and knocking some food into the water below. If I recall correctly, I was due to leave that day for a family vacation and I didn't have any of those dissolving fish food tablets, so I had to rig something up as quickly as possible.
It worked in the end, though!
## Software
[GitHub Repo Link](https://github.com/TheWhetherMan/timed-fish-feeder)
## Code Samples
The entire program is given below:
```c
/**
* Automatic Fish Feeder
* 12/19/14
**/
#include <Servo.h>
#include <Time.h>
#include <TimeAlarms.h>
Servo servo;
int LEDPin = 5;
int motorPin = 9;
int days = 0;
unsigned long time = 0;
void setup() {
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
time = millis();
}
void loop() {
Serial.println(time);
delay(1000);
// 86,400,000 = 1 day
// Note: MUST POWER UP AT DESIRED TIME
if (time >= 86400000 && days <= 4) {
dispenseFood();
days++;
time = 0;
}
time = millis();
}
// Call LED flash and motor methods
void dispenseFood() {
for (int i = 0; i < 5; i++) {
flashLED();
}
spinMotor();
}
// Vibrate the dispensor tray
void spinMotor() {
digitalWrite(motorPin, HIGH);
delay(100);
digitalWrite(motorPin, LOW);
}
// Pulse alert LED
void flashLED() {
// Use PWM for LED on
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(LEDPin, fadeValue);
delay(5);
}
delay(500);
// Use PWM for LED off
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
analogWrite(LEDPin, fadeValue);
delay(30);
}
}
// Print clock to serial port
void digitalClockDisplay()
{
// Digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
```
#development #embedded #arduino #fish #projects