code
/*
By Roee Bloch Fish feeder improved
All right Reserved
Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com
This source is subject to the Roee Bloch License.
Please see the License.txt file for more information.
All other rights reserved.
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
</copyright>
<author>Roee Bloch</author>
<email>roeebloch@walla.co.il</email>
<date>August 2015</date>
also took servo from here:
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
#include <EEPROM.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int time1, time2; // time
int data, degree1;
int first_run = 0;
int minutes, hours;
void setup()
{
degree1 = EEPROM.read(0); // reading address 0
myservo.attach(9); // attaches the servo on pin 9 to the servo object
delay(50);
myservo.write(degree1);
Serial.begin(9600);
time1 = millis();
// Serial.println(time1);
}
void loop()
{
if (first_run == 0) {
// waiting for reset command 30 seconds
Serial.println("waiting for Servo reset command to ZERO degrees, hours and minutes, press 'r' and ENTER to RESET");
time2 = millis();
while ((time2 - time1) < 10000) // we are in first 30 seconds waiting for commands
{
data = Serial.read();
if (Serial.available() > 0) {
// read the incoming byte:
data = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(data, DEC);
if (data == 114)
{
Serial.println("Reset to Zero degrees now and eeprom");
EEPROM.write(0, 0); // wiriting address 0 value 0 // not in use now
EEPROM.write(1, 0); // reseting hours
EEPROM.write(2, 0); // reseting minutes
}
Serial.flush();
}
time2 = millis();
}
Serial.println("Time passed - code continue");
first_run = 1;
}
hours = EEPROM.read(1); // reading hours
minutes = EEPROM.read(2); // reading hours
Serial.println("hours that passed");
Serial.println(hours);
Serial.println("minutes that passed");
Serial.println(minutes);
if (hours == 23)
{
Serial.println("Reseting hours to ZERO");
hours = 0;
}
if (minutes == 59)
{
Serial.println("Reseting minutes to ZERO");
minutes = 0;
}
while(1) // never ending loop
{
wait_day();
for (int x=0; x<4;x++)
{
myservo.write(0); // sets the servo position to 0
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);
}
}
}
void wait_day()
{
for (int y = hours; y < 24; y++) //counting 24 hours
{
EEPROM.write(1, y); // saving hours
for (int x = minutes; x < 60; x++) //minutes delay
{
EEPROM.write(2, x); // saving hours
delay(60000);
// delay(15); //for debug
}
}
Serial.println("day passed!");
//reseting hours and minutes now
hours = 0;
minutes = 0;
}
This code uses Servo motor, and just 2 holes in circular plastic box
Every 24 hours that box will rotate 4 times throwing food out of holes
if there was electricity power off – when the power on again it will continue from last time
Since it saves hours and minutes to ARDUINO memory
Ebay link to bu Arduino Mega: [adsenseyu2]
Ebay link to bu Arduino Uno: [adsenseyu3]
Ebay link to bu Arduino Nano: [adsenseyu4]