Hello everyone,
I will be performing an associative learning experiment where I will try to see if fish can associate a light with a food reward. Given that this is nature of my experiment, I will need the feeder to stick to a very strict schedule. I would like to feeder to feed at 10 AM, 12 PM, 2 PM, and 4 PM, then stop for the day until the next morning at 10 AM, then pick up on the schedule of 12 PM, then 2 PM, etc.
So far, I will be using: an Arduino UNO, two Micro Servos (2730765), a ring of LED lights in a circular plastic tube, and a DS3231 RTC.
I will be using the two example sketches: Blink and Sweep
My fish will be subject to different treatments. Some will have the LEDs light up and the servo deliver the food reward simultaneously. For others, there will be light delays (i.e. 5 sec after light goes on, 10
sec after light goes on) for when the servo goes on.
I would first like to say that I have absolutely 0 experience with programming, so I am very lost as to how I use the RTC to reference the time, and then have the servo motors move at that time.
I'm under the assumption that these will be the two codes I need.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
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
}
}
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
void setup() {
Serial.begin(9600);
while (!Serial) ; // wait for serial
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
}
void loop() {
tmElements_t tm;
if (RTC.read(tm)) {
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}