Timing not keeping to programmed times?

Ive set a water pump up controlled by the Arduino. Ive set it to 40 seconds off 50 secs on (example) and I need to change the time to suit my need. It dosent keep to the timings set? Going for somethuing like 2 mins off 1min 30 on even though it programmed for 40/50?
Any ideas please?
Its driving a 12 volt relay to switch it on and off.
Thank you for any help

Ummm, maybe your program is not working correctly. :slight_smile:

I think we'll need more information. I'm not an arduino freak but those that are will need to see your code I suspect.

Ok ty ill sort it all out and reply

This sounds like a modified blinking LED program.

loop
wait_some_time
pin_on
wait_some_time
pin_off

except you are driving a relay (through a transistor?)
and the wait times are a wee bit longer.

Does the program do any other function?

Another question, the time you're getting is wrong but is it random or constant?

Random would point to a variable being corrupted or maybe using an uint8 at one point but thinking it's a uint16 somewhere else.

Yes through a transistor.
yes thats the programme , very simple, off then on like u say.

its constant wrong time, seems worse if i went up higher times like 1 min

Constant is good, better that some wierd-arsed random problem caused by a spurious interrupt you can never find.

How do you get a 50 sec delay? that's a long time. Does the arduino have a Wait(5000000000) command?

Could you post your complete sketch in between [ code] [/code] tags (the # button when posting)?
If we have that, we can provide you with a solution (and the cause of the issue).

Below is set for 40 sec off 30 sec on. anything over 30 seconds it seems to get confused?

Hope you can see something wrong?
Thank you everyone.

//

int ledPin = 13;
int time_off = 1;
int time_on = 1;

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
time_off = time_off * 40000; // convert to milliseconds
time_on = time_on * 30000; // convert to milliseconds
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(time_on); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(time_off); // wait for a second
}

The maximum value for an int time_on and time_off) is 32,767. Change the type to unsigned int, long, or unsigned long.

Please forgive me but im a novice with Arduino, could you explain how to do the change? Sorry but thank you!!

PaulS, does this mean I can use it for longer times?
Im not understanding what to change and where. Sorry
Thank you so much!!

[glow]int [/glow]time_off = 1;

The variable type is currently int. Change it to unsigned long. Then, you can use it to have the LED off (or on) for longer than 32 seconds. Much longer.

Sorry to be a pain, can you show me what you mean and where to put this?

An example maybe so i understand what to do.
Thank you again

He is trying to tell you to change

int ledPin = 13;
int time_off = 1;
int time_on = 1;

to:

int ledPin = 13;
unsigned long time_off = 1;
unsigned long = 1;

PaulS did show you, but to spell it out a bit more

int time_off = 1;
int time_on = 1;

should be 

[glow]long[/glow] time_off = 1;
[glow]long[/glow] time_on = 1;

an int is only good for values up to +-32k, a long can handle values to +-2gig. unsigned long can handle values to 4gig.
also, for clearer coding you don't mutiply something by 30000 or 40000 to turn it into milliseconds. It's clearer to have the number of seconds in a variable then x that by 1000.

long time_off = 40;
long time_on = 30;

void setup()   {                
 // initialize the digital pin as an output:
 pinMode(ledPin, OUTPUT);     
 time_off = time_off * 1000; // convert to milliseconds
 time_on = time_on * 1000; // convert to milliseconds
}

and while we're at it you can tidy up a bit more with

time_off *= 1000; // convert to milliseconds
time_on *=  1000; // convert to milliseconds

for that matter ditch the lot

long time_off = 40 * 1000;
long time_on = 30 * 1000;

void setup()   {                
 // initialize the digital pin as an output:
 pinMode(ledPin, OUTPUT);     
}

Most of the above will generate the same run-time code but you'll find as you start writing longer programs it's important to make things as clear as possible.

YES Guys!!!!! sorted!!!!
thank you for bearing with me!!!
Many many thanks.