1

I am trying to make a auto fish feeder to feed my fish every 6hours. I want to implement RTC module to my code. So far I've been using only an arduino and a servo using this as a code:

#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 myservo.write(15); }

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 } // Wait for 12h delay(6 * 3600000); }

The RTC module I have is the DS1302. It's library cn be downloaded here The code for the clock is this:

// DS1302_Serial_Hard 
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS1302-library to 
// retrieve time- and date-date for you to manipulate.
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302 DS1302 rtc(2, 3, 4);

// Init a Time-data structure Time t;

void setup() { // Set the clock to run-mode, and disable the write protection rtc.halt(false); rtc.writeProtect(false);

// Setup Serial connection Serial.begin(9600);

// The following lines can be commented out to use the values already stored in the DS1302 rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format) rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010 }

void loop() { // Get data from the DS1302 t = rtc.getTime();

// Send date over serial connection Serial.print("Today is the "); Serial.print(t.date, DEC); Serial.print(". day of "); Serial.print(rtc.getMonthStr()); Serial.print(" in the year "); Serial.print(t.year, DEC); Serial.println(".");

// Send Day-of-Week and time Serial.print("It is the "); Serial.print(t.dow, DEC); Serial.print(". day of the week (counting monday as the 1th), and it has passed "); Serial.print(t.hour, DEC); Serial.print(" hour(s), "); Serial.print(t.min, DEC); Serial.print(" minute(s) and "); Serial.print(t.sec, DEC); Serial.println(" second(s) since midnight.");

// Send a divider for readability Serial.println(" - - - - - - - - - - - - - - - - - - - - -");

// Wait one second before repeating :) delay (1000); }

So the question here is, how can I set up my code to work with RTC, in order to move the servo every 6 hours?

1 Answers1

1

You have to spend some time and practice coding, it does not come over night. As far as your timing look up for an alarm clock sketch that will do what you want. Once you understand that you should only have to add a few lines of code. As far as open source the tools you are using are open source. Remember there are people out there that are expertes and there people just starting so expect what you find to fall some in that range of quality.

Gil
  • 1,863
  • 9
  • 17