Timer

Hello Friends,

I am doing a switching circuit using arduino.Here i need to switch a relay in different time depends on the reading of a potentiometer.For example if the POT is in one position then switch relay in every2 hour,if change POT value to next then switch relay in every 3 hours and so on.I want you help to suggest me which one is the best option to select this time delay of 2,3,4 hours......i need a perfect time delay,any one have the timer library of perfect and correct timer delay?please help me...Thank you

Use the millis timer, it is as good as anything else that uses the clock on an Arduino.

Grumpy_Mike: Use the millis timer

thank you friends...thanks for your helping mind...

friend i used it,i modified the program to a delay of 25 second with a variable but i get about 32 second in result.. here i attached my program below for your kind perusal.. please help me...i dont know the program i did is right method or not, i invite your attention to my program..thank you very much

const int ledPin = 13; // the number of the LED pin int ledState = LOW; // ledState used to set the LED int i=0;

unsigned long previousMillis = 0; // will store last time LED was updated

const long interval = 1000; // interval at which to blink (milliseconds)

void setup() { pinMode(ledPin, OUTPUT); }

void loop() {

unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; i++;

if(i==25) {

if (ledState == LOW) { ledState = HIGH; } else { ledState = LOW; } i=0; }

digitalWrite(ledPin, ledState); } }

Please read this:- How to use this forum Because your post is breaking the rules about posting code.

Well when I run your code I get 25 seconds delay.

but i get about 32 second in result.

It looks like your Arduino clock is running slow. Is it a real Arduino or a rip off clone? Does it have a crystal or a resonator?

Grumpy_Mike: Please read this:- How to use this forum Because your post is breaking the rules about posting code.

Well when I run your code I get 25 seconds delay. It looks like your Arduino clock is running slow. Is it a real Arduino or a rip off clone? Does it have a crystal or a resonator?

Hello friend thanks for your reply....

i read the rules and i will use the code tags next time.. sorry for the error.... and i got the error ..its because of the crystal value.. thank you very much for your help.i appreciate your helping mentality

Also if you are timing the first interval from start up or reset there is the boot negotiations to factor in. This will add about two seconds to the first interval only.