could you explain please. Which closing brace do you mean and what should i do with Wire.h?
Thanx
could you explain please. Which closing brace do you mean and what should i do with Wire.h?
Thanx
This compiled for me under IDE 1.0.4:
// basic two relay board timed animal feeder
// relay is turned on for two seconds at approx. 12hr intervals to spin 12v motor.
#include <Wire.h>
#include "RTClib.h"
// define names for the 4 Digital pins On the Arduino 7,8,
// These data pins link to 2 Relay board pins IN1, IN2,
#define RELAY1 7
#define RELAY2 8
#define FEED_DELAY 2000 // 2 seconds
#define IDLE_DELAY 30000 // 30 seconds
#define POST_FEED_DELAY 60000 // 60 seconds // could be longer (4 hrs even)
RTC_DS1307 RTC;
void setup() {
// Initialise the Arduino data pins for OUTPUT
pinMode(RELAY2, OUTPUT);
RTC.begin();
if (!RTC.isrunning()) {
// you need some means of reporting error. Could be one of the other relays.
//Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(_15_DATE_01_, _11_TIME_51_));
}
}
// Function to operate the motor and feed the deer
void do_feed(){
digitalWrite(RELAY1, LOW); // Turn ON Relay 1
delay(FEED_DELAY); // Wait for hopper to fill
digitalWrite(RELAY1, HIGH); // Turn Relay Off
}
// Function to determine if it is feeding time
boolean is_feed_time(int hour, int minute){
if(hour == 16 && minute == 0) {
return true;
}
return false;
}
// main loop
void loop(){
// poll the RTC for the time of day.
DateTime now = RTC.now();
int hour = now.hour();
int minute = now.minute();
if(is_feed_time(hour, minute)){
do_feed();
delay(POST_FEED_DELAY); // Wait enough to prevent double feeding
} else {
delay(IDLE_DELAY); // Wait a small amount before
}
}
THANK YOU!
I have it uploaded.
Now my motor should come on at 5 am and 4 pm, correct?
I am getting excited now.
Thanx
OK I did not notice that I inadvertently erased the first feed time somehow. It should state on at 5am for two seconds then on at 1600 for two seconds. And when I put that code in it errors again.
I don't understand the errors and can't find much ...YET, on how to read them.Will play some more,just do not want to fry anything.
My friend says I need a means of reporting errors but failed to tell me how I might do this or why I would want to.
If you can help I would appreciate it.
Thanx
Can't help much without the latest code.
late to the party....
if you have a project that is running pretty well, but you want to try some totally new stuff, you would really want a second, matching arduino. for testing, I like the UNO because you can just pop on a shield and add things.
when buying a matching units, make sure you get the same USB chip.
in your case, you can buy a real time clock with an SD card and then data log your unit
I would offer that you data log every hour, then when you load the data onto your PC, you can see when any errors occur.
you could write a sketch to data log as part of any event, but if that event fails, you may not get the log as well.
Is it necessary for this project to have a data log?
This will be set out in the woods on its own. I will be checking that feed is topped up every few weeks
the "newer sketch" is
// basic two relay board timed animal feeder
// relay is turned on for two seconds at approx. 12hr intervals to spin 12v motor.#include "RTClib.h"
#include <Wire.h>
// define names for the 2 Digital pins On the Arduino 7,8,
// These data pins link to 2 Relay board pins IN1, IN2,#define RELAY1 7
#define RELAY2 8#define FEED_DELAY 2000 // 2 seconds
#define IDLE_DELAY 30000 // 30 seconds
#define POST_FEED_DELAY 60000 // 60 seconds // could be longer (4 hrs even)RTC_DS1307 RTC;
void setup() {
// Initialise the Arduino data pins for OUTPUT
pinMode(RELAY2, OUTPUT);
RTC.begin();
RTC.adjust(DateTime(DATE, TIME));
if (!RTC.isrunning()) {
// you need some means of reporting error. Could be one of the other relays.
//Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(15_DATE_01, 11_TIME_51));
}
}// Function to operate the motor and feed the deer
void do_feed(){
digitalWrite(RELAY1, LOW); // Turn ON Relay 1
delay(FEED_DELAY); // Wait for hopper to fill
digitalWrite(RELAY1, HIGH); // Turn Relay Off
}// Function to determine if it is feeding time
boolean is_feed_time(int hour, int minute){if(hour == 5 && minute ==0) {
return true;}if(hour == 16 && minute == 0) {
return true;
}return false;
}// main loop
void loop(){
// poll the RTC for the time of day.
DateTime now = RTC.now();
int hour = now.hour();
int minute = now.minute();if(is_feed_time(hour, minute)){
do_feed();
delay(POST_FEED_DELAY); // Wait enough to prevent double feeding
} else {
delay(IDLE_DELAY); // Wait a small amount before
}
}
I don't know why the delay and post delay are there either, just the way he did it for me, can't reach him on weekend.
The order of these two is important:
#include <Wire.h>
#include "RTClib.h"
that 60000 may cause issues - too big to fit in a signed int, better:
#define POST_FEED_DELAY 60000UL // 60 seconds // could be longer (4 hrs even)
The post_feed_delay is to ensure that the next minute has ticked over on the RTC so that you don't give the deer multiple rations at feeding time.
The idle_delay is there just because. There's not point checking the RTC more than once a minute, so a thirty second delay ensures that the code doesn't continuously poll the clock. On the other hand, the arduino has nothing better to do, so there's no actual need for a delay. It's possible there may be some slight power savings to be made by avoiding a continuous read.
Wow , Added that and it compiled.
But it turns the #1 relay on and it stays on.
Tried changing time to present time and same thing
Thanx for help
You don't have a pinmode call for RELAY1 in setup. Since you don't use RELAY2 anywhere, I assume there's a typo and this:
pinMode(RELAY2, OUTPUT);
should actually be:
pinMode(RELAY1, OUTPUT);
Tried changing those two around and it just calls for what ever relay is selected and it stays on, which means the motor runs constantly. Of course I tried changing the wires over to other side of each relay also,to normally closed, and then changed time to come on and it didn't kick in .Maybe there is a problem with rtc code, when I check serial with timed feeder library loaded i don't see anything for time or date, or is this normal?
Here is how it is wired and pictures of it as it sits now. Thought I might have fried something so I disconnected all wiring an ran some examples through uno alone and all was well.
Maybe the two positive cables going to 5v are wrong? Don't know where else it might go.
Possibly some wiring wrong for the code but thought I changed and tested code to eliminate that.
Found out friend is on a cruise and internet is very sketchy.
Well if anyone sees what I did wrong please let me know.
Thanx
well got code to work and it seemed to be fine, but it will not run more than 4 days on an 18AH 12 v battery and small solar panel. Is this normally a problem with arduino in general ?
anyone able to tell me if this is normal battery use for the arduino? I think it was Bill who mentioned the time polling.Can I change that to only check the time every 6 hours or even better every 10 - 12.? The motor only runs for 3 seconds and then it is idle the rest of the time. I am using a sealed battery 18 Ah fully charged with a small coleman solar panel. I figured this would last . My other feeder runs on 4 AA but it is factory and actually has a digital clock that displays all the time and it lasts approximately a year. Also will upload the working code if this will help or if anyone is interested and can maybe use house power.
Thanx
Thanks for posting this up,
I have one small question, is it ok to use my dog feeder for the deer?
Battery backup...
Why fight with something, if you can go around it??
Do you need to feed at night?
Would it matter if the system "died" at dusk each day? Just build something that can survive a daily power supply failure, and you can forget all the battery backup headaches! (You'll still need the solar panels.... mostly to power the spinner motor, but some current will also be needed for the Arduino.... but it doesn't have to be 24/7 power, unless you want to feed at night.)
Either use a little Real Time Clock module (with a LITTLE "coin cell" to keep it alive when everything else is dead) or use a light sensor, and software to detect dawn, and feed at the time of your choice, after dawn.
Now... this next bit is telling you more than I know... but, "best guess" after many hours struggle...
Microprocessors can sometimes lock up if their supply voltage rises slowly... unless you're talking something with "brownout protection"... which, in this case, might better be called "brownUP protection". So, if you are letting the system die at dusk, and revive when the sun is high enough in the sky, you risk these (not permanent) lock-ups. I think.
But! Nick Gammon has figured out the answer to that. And I've been working on a PCB to implement the circuit he came up with. For your wants, if you like my "answer", you would skip the supercap and 3v3 regulator in my implementation of Nick's circuit... or just use what's at the page I'm about to cite as a starting point for a purpose-built circuit. It wouldn't, actually, be hard, and not at all expensive. Just "getting there", i.e. getting to the point where you are set up, and know how, to do ATtiny programming and fusing is a little tedious. (Not expensive, though!) I hope my pages, even in their early state, at 02 Dec 17, will help you with that. PCB 269- Solar Power with overnight standby
As a cynical aside, as for....
Deer Feeders Illegal? All 100 of these?
... Hmm. "They" make all sorts of laws. I suppose they think it will get them votes. But do they then enforce them? Makes it all a bit of a joke, doesn't it? Sigh. And they make dear baiting illeagal, but not the sale of equipment for baiting. (Yes, I do understand that equipment can sometimes have legitimate uses as well as illegitimate.)