Best way to add one hour waiting time

i am using arduino and relay to control my pump motor.After i turning on the pump motor it should run one hour.After one hour pump should be off.What is the best way to add one hour time without using delay function

What is the best way to add one hour time without using delay function

Define "best way"

You can use the BWD (Blink Without Delay) technique to do this.
You can use an RTC.

http://forum.arduino.cc/index.php?topic=503368.0

.

i dont have RTC.i need to do multitasking.after relay turned on it should start timer.at the same time it has to run other loop functions.When the time meets one hour relay interrupt should go low.if i am using delay function entire loop will stop for that time.so i need some idea without using delay function and RTC

anbu123:
i dont have RTC.i need to do multitasking.after relay turned on it should start timer.at the same time it has to run other loop functions.When the time meets one hour relay interrupt should go low.if i am using delay function entire loop will stop for that time.so i need some idea without using delay function and RTC

anbu123:
i am using arduino and relay to control my pump motor.After i turning on the pump motor it should run one hour.After one hour pump should be off.What is the best way to add one hour time without using delay function

Hi

Like larryd wrote, use millis() to calculate 0 to 3.600.000 while waiting. BlinkWithoutDelay -example will push you on right path regarding that. An issue could be in this case if your Arduino will boot while calculating. To prevent that issue you could use EEPROM to store time for power loss / boot

TommiP

The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

...R

thanks to all :slight_smile:

@TommiP, how is EEPROM going to solve that? If the Arduino is off the timer isn't running. And when it starts again millis() return 0 again.

@anbu123, remember the Arduino clock isn't that precise. It's precise enough to time an hour for most applications though. But if you want to run the pump 1 hour every day that's another story. Because then you also need to time the 23 hours in between and the error will just accumulate. A few seconds on an hour isn't a big deal (for most applications) but for example 5 seconds an hours is 14 minutes after a week.

Is something else defines the start then you start fresh every day and you just have the small error. If you can live with that small (possible) error is up to you.

septillion:
@TommiP, how is EEPROM going to solve that? If the Arduino is off the timer isn't running. And when it starts again millis() return 0 again.

You could mark where you were..

TommiP

Depends on the application if that's useful or not. But you're right if the pump also stops when the Arduino turns off and you want it to run for the remaining time when the Arduino starts. Only problem, you can't just write to EEPROM every second because you will run out of write cycles of the EEPROM pretty quick...

septillion:
Only problem, you can't just write to EEPROM every second because you will run out of write cycles of the EEPROM pretty quick...

Correct. You have to find a way to write when the power is almost out. In other words, you have to have something to keep arduino alive until it has written EEPROM and then it could shut down.

TommiP

anbu123:
i am using arduino and relay to control my pump motor.After i turning on the pump motor it should run one hour.After one hour pump should be off.What is the best way to add one hour time without using delay function

to make sure I understand.
you walk up to the button and press it.
then, the pump runs for one hour.
then shuts off.
if, at any time, you press again, something happens
either it counts to that one hour you said, and ignores new button presses
or, it looks at the last button press and then runs for one hour after the last button press.
if you pressed it, 20 times in one minute, then one hour and one minute later, the pump would go off.
you can do either with blink without delay.

while that pump us running (or not) and you press button #2, then you could have pump #2 run for one hour. if say, 11 minutes and 37 seconds later, you pressed button #1, then pump #2 would shut off in 48 minutes and 23 seconds, and pump #1 would shut off in 60 minutes.
you could watch for rain, measure temperature, or water level, or all sorts of things, while the timer is running on each of many, many pumps.

TommiP:
Correct. You have to find a way to write when the power is almost out. In other words, you have to have something to keep arduino alive until it has written EEPROM and then it could shut down.

TommiP

yes, but it would make a lot more sense to add an RTC for 99 cents.
also, we would assume that the pump would shut off when the Arduino looses power.
you could use a battery backup and run the Arduino and relay for the pump for 1 hour with a simple battery. no need to store the time.
many ways to get this to work.
I would offer that if you used the same power source as the pump, the point becomes moot.
on the other hand... if you needed to add water to the lawn and needed the pump to run for 1 hour, regardless if the power was interrupted, you would need a battery or cap, to hold power, know power was lost, write to eeprom, then let the unit die for 1 second or hours and hours and days and days....
....then come back on for however many seconds are left.......

dave-in-nj:
yes, but it would make a lot more sense to add an RTC for 99 cents.

I agree but I respected anbu123's wish to find a solution without RTC.

anbu123:
i need some idea without using delay function and RTC

TommiP