Go Down

Topic: Timekeeping without RTC+ Interrupt? (Read 295 times) previous topic - next topic

istvanuino

Hi!

My first packege with Arudino stuff is on it´s way for my home automation projects are taking form in my head.

My first project will be a dry food feeder for the dog.
Thought a servo that can rotate continuously will turn the feeder for X ms for the right amount of dry food.
Then the Arduino will wait for 24 hours before it´s time again.
This way if I want to food the dog 18:00, I just power on the Arduino at 18:00 and it will dispense dryfood every 24 hour.

How can I program the Arduino to wait 24 hours without a RTC chip?
I checked this but I can´t see how the int can keep that high amount of miliseconds
http://www.gammon.com.au/blink

Also, there will be a button, if pressed it will dispense some additional food.
(That would be the interrupt).

Can I start a counter when the Arduino is powered on and use a IF when the counter have waited for 24 hours?

For example:

void setup()
{
  TempServo.attach(13);
  Ini 24Timer start
}

void loop()
{
IF 24timer = 24hours;
  TempServo.write(110); //Dispense food
  delay(1800);

IF Button = 1
  TempServo.write(110); //Dispense food
  delay(1800);
}

KeithRB

You certainly can, but it is not very accurate. If your dog does not mind changing its feeding time a few minutes each day...

But you don't need interrupts. For something like this simply *polling the RTC every second or so would be sufficient.

*polling means that you regularly ask the RTC what time it is.

istvanuino

Why is the Arduino timer not accurate? (Minutes change every day).

Also I do not have an RTC chip.
Thant´s why I ask about timer (Or something similar)

istvanuino

Maybe I can use the "millis()" ?
Or will it not be accurate either?

Delta_G

Accuracy is relative. The dog won't mind a minute or two off, so millis is fine to use.

If at first you don't succeed, up - home - sudo - enter.

istvanuino

Will the timer add one or two minutes every time? Or the Arduino execute the code 18:00 plusminus 2 minutes?

Delta_G

Will the timer add one or two minutes every time? Or the Arduino execute the code 18:00 plusminus 2 minutes?

Maybe a minute more. Maybe less. It will drift a little. The dog won't notice.
If at first you don't succeed, up - home - sudo - enter.

odometer

I checked this but I can´t see how the int can keep that high amount of miliseconds
https://www.arduino.cc/en/Reference/Delay
Apparently, the delay() function takes an unsigned long as input. Go ahead, try delay(86400000UL) and see what happens.

sterretje

One other problem that you will more than likely encounter is a power failure / reset of the arduino. You're timing will be lost. You also might need to set the initial time or start the Arduino at 'exactly' 6 o'clock.

A RTC is a million times ( ;) ) easier.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up