raschemmel:
You need to buy one because you can't use millis() if you need it to do something everymorning at 6:00am.
For the OP's knowledge, can you also explain why not?
You can make a circadian clock, it will not run exact at 6:00 AM but it will be probably close enough.
Monitor dawn and dusk with an LDR on an analog port.
The middle in between (LDR dark) is midnight. 00:00:00
Rest can be calculated reasonably well with millis()
synchronizes every day auto magically with solar time.
see also - http://fgh.si/post/32338612783/circadian-clock-for-arduino -
For the OP's knowledge, can you also explain why not?
Millis() is limited to the maximum size number the arduino can process , (232=4294967296, which comes out to 49.71026962962962962962962962963 days. (4294967296/1000/60/60/24=49.71026962962962962962962962963)
First you need to know when is 6:00am (at least the arduino does) . If you hardcoded it to start at a specific time knowing how many milliseonds remain to 6:00 am, you would still have to deal with the rollover every 49.7 days.
robtillaart is a real programmer (wheras I am a quasi-hack pseudo programmer) so he might be able to explain it better.
No RTC needed. Run a clock program, just monitor the time variables and do something when 0:6:0:0 is reached.
If you happen to lose power, restart it - or run it from battery:
The advantage of my way is that you're not doing a bunch of slow modulo stuff to break out the digits - they're already broken out - and all ready to send to a shift register for 7-segment display or similar.
CrossRoads:
The advantage of my way is that you're not doing a bunch of slow modulo stuff to break out the digits - they're already broken out - and all ready to send to a shift register for 7-segment display or similar.
Fair enough, but I'd rather push off the Unix -> digits stuff into a single function than have to constantly deal with all over the place.
All over the place? Loop as written is that one function.
For hardware output use, I replace the Serial.prints with SPI.transfer commands to send the data out with a font lookup:
I mean every time I want compare one time to another or schedule something to happen in the future. Unix timestamps can be evaluated with <, ==, > instead of a bunch of && for each digit.
My advice would be to go with using millis() in the first instance. It will not be entirely accurate but only requires one comparison each time through loop() to establish whether the required period has elapsed.
Look at the solution suggested by robtillaart. Other solutions may be more accurate, neater, cleverer etc but you have to start somewhere.
bentech4u:
after seeing all of these , i got confused. Which one i need to follow?
Don't mind us, we like to wax philosophical here.
As for which one to use, you need to decide if you're okay with a little drift (after a few days, your motor runs at 6:01am or 5:59am, and a few days later, at 6:02am or 5:58am, etc).
If you're okay with drift, then robtillaart's reply #8 is simple and will work just fine for you.
If you're not okay with drift, then you either need to be near a window so you can use a sensor to detect sunrise/sunset, or you need to use a DS3231 RTC.
Little time changes are ok for me as this is to make a fish food feeder.
is it possible to print the time to one lcd (16*2) lcd module. so that i can able to see the status noe? like every day it started on what time and all
i have uploaded the code to IDE and i got some error like below: