need help with millis() rollover for growduino!!!

 if(pump_on == 0)
     {
     if ((lastmillis - last_pump_off) > pump_delay)
       {
       digitalWrite(pump_pin, HIGH);
       pump_on = 1; // here is the problem
       last_pump_on = lastmillis;
       }
     }
  
       //PUMP ON -> OFF
   if(pump_on == 1)  // as you have no else, it will match, and turn off pump (i think)

Same goes for the LED part.

if that were the probem, it would happen right away, not after 22 hours. No else is needed because last_pump_on is updated and by

if ((lastmillis - last_pump_on) > pump_delay)

it is made sure that we wait at least pump_delay milliseconds before turning the pump off again.

Thanks for your answers! The 9v doesn't come from a 9v battery, it come from a wall plug that I bought from adafruit. I'll add a serial print function to my code as PaulS suggested. Maybe we will then understand better what's going on. I'll also try to add a delay at the end of my code, to avoid having the software running in loop to quickly.

Okay, here is my new code. You made me try Serial.print for the first time!!! And it's pretty easy...

//By Martin Rioux
  
       //GENERAL
   unsigned long lastmillis = 0;  
  
       //PUMP (WATER PUMP)
   int pump_pin = 3;
   int pump_on = 0; // 0=OFF, 1=ON  
   unsigned long last_pump_on = 0;
   unsigned long last_pump_off = 0;
   unsigned long pump_delay = 300000;       //PUMP TIME OFF
   unsigned long pump_duration = 300000;    //PUMP TIME ON
  
       //LED (STATUS LED, BLINK EVERY SEC)
   int led_pin = 2;        
   int led_on = 0;
   unsigned long last_led_on = 0;
   unsigned long last_led_off = 0;
   unsigned long led_duration = 1000;  //LED BLINK DELAY (1 SEC ON, 1 SEC OFF)

  
   void setup()
   {
       //PUMP SETUP
   pinMode(pump_pin, OUTPUT);    
   last_pump_on = 0;
   last_pump_off = 0;

       //LED SETUP
   pinMode(led_pin, OUTPUT);    
   last_led_on = 0;
   last_led_off = 0 ;
   
       //SERIAL PRINT SETUP
   Serial.begin(9600);    
   }

  
   void loop()
   {  

       // RESET TIMER WHEN ROLLOVER
   if (lastmillis > millis())    
     {
     last_pump_on = 0;
     last_pump_off = 0;
     last_led_on = 0;
     last_led_off = 0;
     lastmillis = 0;
     digitalWrite(pump_pin, HIGH);
     digitalWrite(led_pin, HIGH);
     Serial.print("Rollover! : ");
     Serial.println(lastmillis);
     }                          
  
       //GENERAL CYCLE START
   lastmillis = millis();    

       //PUMP OFF -> ON
   if(pump_on == 0)
     {
     if ((lastmillis - last_pump_off) > pump_delay)
       {
       digitalWrite(pump_pin, HIGH);
       pump_on = 1;
       last_pump_on = lastmillis;
       Serial.print("PUMP OFF->ON : ");
       Serial.println(lastmillis);
       }
     }
  
       //PUMP ON -> OFF
   if(pump_on == 1)
     {
     if ((lastmillis - last_pump_on) > pump_duration)
       {
       digitalWrite(pump_pin, LOW);
       pump_on = 0;
       last_pump_off = lastmillis;
       Serial.print("PUMP ON->OFF : ");
       Serial.println(lastmillis);
       }
     }                          
  
       //LED OFF -> ON
   if(led_on == 0)              
     {
     if ((lastmillis - last_led_off) > led_duration)
       {
       digitalWrite(led_pin, HIGH);
       led_on = 1;
       last_led_on = lastmillis;
       Serial.print("LED OFF->ON : ");
       Serial.println(lastmillis);
       }
     }                          
  
       //LED ON -> OFF  
   if(led_on == 1)              
     {
     if ((lastmillis - last_led_on) > led_duration)
       {
       digitalWrite(led_pin, LOW);
       led_on = 0;
       last_led_off = lastmillis;
       Serial.print("LED ON->OFF : ");
       Serial.println(lastmillis);
       }
     }  
   Serial.print("Millis : ");
   Serial.println (millis());
   delay(1000);    //WAIT
   }   //void loop()

You made me try Serial.print for the first time!!!

Your kidding, right? How have you been debugging this?

You getting any output?

In fact, it is the first time I write the serial.print code myself. The other time I used the serial.print function, it was made by a friend. The code wasn't the same, but the result was exactly the same (15-20 hours before it jam). There was no good information in the serial.print at that time, but I hope there will be for this code!

Right now, the serial monitor work perfectly well, showing me when the led or pump turn on or off, and the current millis. At 8h00 am tomorrow, it'll probably crash again and I'll send you the last data I've got from it. When this test will be done, I'll try a simple program to blink a LED only with delay to see if it crash. If the blinking LED crash, my board is probably just broken in some weird kind of way.

It's now been 24 hours since I started the software, but my computer rebooted this night.... I've started it again this morning at 8h00.... Lets hope this stupid computer keep running.

PS: I hate automatic update

I noticed it was crashed at 6:50 this morning. Here is the last thing I see in the serial monitor :

The pump was turned on or off every 30,000 millis

PUMP ON->OFF : 2826293847 ... (I skipped many lines so you can see the pump millis) PUMP OFF->ON : 2826594388 ... LED ON->OFF : 2826887600 Millis : 2826887633 LED OFF->ON : 2826888647 Millis : 2826888681 LED ON->OFF : 2826889694 Millis : 2826889727 LED OFF->ON : 2826890741 Millis : 2826890775 LED ON->OFF : 2826891788 Millis : 2826891822 LED OFF->ON : 2826892835 Millis : 2826892869 LED ON->OFF : 2826893882 Millis : 2826893916 PUMP O

I don't understand anything... It just stopped on the O of ON

The LED and the pump stopped working on the OFF State

Thanks for you help!

Millis: 2826893916

How fast are millis going over there in Canada? That's enough millis for 32 days.

hey, you are right! But, how is that possible????

Look what happened there!

Millis : 44471586 LED OFF->ON : 44472597 Millis : 44472629 LED ON->OFF : 44473640 Millis : 44473672 PUMP ON->OFF : 44474683 LED OFF->ON : 44474683 Millis : 2795938164 PUMP OFF->ON : 2795939178 LED ON->OFF : 2795939178 Millis : 2795939239 LED OFF->ON : 2795940254 Millis : 2795940288 LED ON->OFF : 2795941301

it skip from 12.35 hours to 32.36 days!!!

Can it be the way my system is connected that shock the arduino when the pump goes ON and make it skip time????

I am now running a simple program to see if this happen always at the same time.

int led_pin = 2;

void setup()
{
pinMode(led_pin, OUTPUT);
Serial.begin(9600); 
}
void loop()
{digitalWrite(led_pin, HIGH);
delay(1000);
digitalWrite(led_pin, LOW);
delay(1000);
Serial.print("millis() = ");
Serial.println(millis());
}

Hmm. The difference between 2795938164 and 44474683 is very nearly 0xA4000000. So something added 164 or wrote 166 to the most significant byte of the millis counter.

If only you had a recursive function call or an excessive amount of variables so we could understand why... ::)

Can it be the way my system is connected that shock the arduino when the pump goes ON and make it skip time????

Are you actually turning the pump off and on during testing, or simply setting the pin HIGH or LOW?

What kind of pump is it? What is actually connected to the pin?

Nothing should make it skip time, but something is clearly wrong.

I am only setting the pump HIGH and LOW, I am not turning it manually. The pump is turned on with a relay. Here is the wiring diagram of my system (It is the same as the original growduino)

http://www.glacialwanderer.com/_blog/blog2008/04_April/hb_relay5.jpg

My pump is a small pump, I can't remember how many watt, but it is not much.

So all you are turning on with the Arduino is a transistor that turns on a relay.

What I wanted to know in my last post was whether the pump is actually being turned on and off (by the Arduino) during the testing. That is, is the pump an active part of the circuit - not just being emulated by an LED.

I don't see any decoupling capacitors in that circuit. Where's Grumpy_Mike with his handy links when you need him?

You may be getting electrical spikes when that relay is opened and closed that are affecting the Arduino. Some capacitors or diodes might help.

If only you had a recursive function call or an excessive amount of variables so we could understand why... ::)

eeehhhh..... yeah? :-?

In my current test, the pump isn't even connected, (I should have mentioned that earlier...) I plugged an old game boy adapter that have a LED on it instead.

But can't it be a problem with the arduino itself??

Can it be the way my system is connected that shock the arduino when the pump goes ON and make it skip time????

In my current test, the pump isn't even connected

But, was the pump (circuit) connected when the time jumped?

My circuit was exactly the same as on the website. It was all connected, but instead of the pump there was my gameboy adapter. It was connected the same way I want it to be when it will be running.