Arduino Timer

Hello to everybody :slight_smile: I would like my arduino to control my pool pump.
So I played around with some of the time lib. Found it very confusing. Especially when
you try to load the sch-etch and get problems like library not found and code that needs to
change for it to work on the arduino 1 software. Please help me.
This is what I need!!!
1 output (pump motor control)
"Set on time"(in code) and "Set off time"(in code) on Automatic loop. Don't need to be precise.
Must come on every x hours. Must Switch off every x hours. Hope it make sense.
Regards
V

if i were you (and i'm not) I should really take a look at the millis() function on the arduino

and is the arduino does not need to do anything else at all you could also use the delay function
http://arduino.cc/en/Reference/Delay
although with the last one you should be carefull if you would like to extend your projects
also watch out that ther is a maximum on delay() (4,294,967,295 milliseconds aprox 49 days)
and on millis() the max will be about

sketch example(with delay):

Boolean On_Off = startposition;
int Hours_on = x;
int Hours_off = y;

//main loop
if (On_Off){               //if the pump should be on
OUTPUT = On_Off;     // output is on
delay(3600000*Hours_off); // delay of x hours
On_Off =! On_Off;      // toggle it off
}

if (!On_Off){              //if the pump should be off
OUTPUT = On_Off;    // output is off
delay(3600000*Hours_off); // delay of y hours
On_Off =! On_Off;     // toggle it on
}

note: the above code is just a mindspin to help you this will not work when copied

Hi daatse.
Thank you for your reply very much appreciated. So this code as you said don't verify,
but it seems you do understand what I am trying to do. Also this will be a ongoing project and next up is a lcd (16,2). One thing you did not say or forgot to mention is the max amount for " millis() " and will that effect my other program flow? . If I could run I timer or alarm to go on at a certain time to switch the pump on for x amount , while busy with other things

in that case i recomand that you use the millis() function, this function will reset due to overflow once in aproxemently 50 day

take a good look at that link and maeby try an example or two like the ledblink without delay

and a timer will allow you to use other functions will maintaining a propper timing
if i may, i really would like you to try the example, because it is very educational

Thanks for the links. Will take a look and report back.

OK looking at the code http://arduino.cc/en/Tutorial/BlinkWithoutDelay
I think it could work. The interval seems to be the same amount on and off.
So how to go from here?

So I uploaded the sketch just fine and change time "long interval = 10000000; // interval at which to blink (milliseconds) just tinkering around. So next up is to test it and it started and running for a hour now.

daatse:
if i were you (and i'm not) I should really take a look at the millis() function on the arduino
millis() - Arduino Reference

Hello Daatse.
I decided to play with that code so I add a lcd and ended up with using delay :astonished: , but
it is just to watch the time fly by while I still figuring out what to do :slight_smile:

#include <LiquidCrystal.h> // For the 2x16 LCD status screen
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long time;

void setup(){
lcd.begin(16,4); // 16x2 LCD Panel //Serial.begin(9600);
lcd.setCursor(0,0);

}
void loop(){
lcd.print("Time: ");
time = millis();
//prints time since program started
lcd.print(time);
delay(1000);
lcd.clear();
// wait a second so as not to send massive amounts of data
delay(100);
}

this is not a mayor problem, the millis() and delay function can work side by side the main difference is

--millis
millis is just a counter which valeu can be aquired by using the function millis(). it wil count since the last reset.
the good part you can run program alongside it
the bad part its slightly less easy to use then delay

--delay
delay is a CPU intensive loop which simply needs to be finnished before the next action can be done
the good part its super easy to use
the bad part it will 'stop' youre programm from looping until the delay is finished

Thanks yet again for your contribution. This is a very steep learning curve , but once I snap it , only then I will complete my own personal high of my career.
Regards to all and lets build the Arduino code library Quickly so that invention can follow. !!!!
NB. check this out for all that need to know more about timers !
http://www.engblaze.com/microcontroller-tutorial-avr-and-arduino-timer-interrupts/