Uno Shutting Down (not heat related)

I am using an Arduino Uno R3 with a DS1307 RTC, driving 27 Super Bright clear LEDs (red, green, blue & yellow), of which there is a maximum of 24 lit any one time, for a period of one minute. The LEDs are being turned off and on at random each second.

I have checked the Uno board with an IR thermometer when the 24 LEDs are lit and the hottest spot, which is just behind the USB connection (not in use), at 29C max.

It has been running 24/7 for weeks without incident. When it shut down I immediately unplugged it and plugged it back in. Dead. Waited about 30 seconds, plugged it back in again, and it has been running for three days now without incidence.

Any ideas as to what to look at as a reason for this behavior?

Unclean reset put processor into non-working state I'd guess? Sometimes briefly removing the power can cause the chip to come back up in a bad state (that's what BOD is for, to ensure chip resets itself if it's powered, but not at a high enough voltage to ensure functioning - but I think it's disabled on the Arduino boards by default). I suspect the reset button would also have revived it by ensuring a proper reset.

Edit: Oh, I missed the part about it shutting down while in use, thought you just unplugged and re-plugged.

How long has it been running? ~50 days by any chance? That's about how long it takes for millis() to roll over.... could the millis rollover be doing it?

Was using the millis() function in the first iteration. It shut down on it's own just like this. Found the reference to millis() rolling over after 50 days, so I rewrote the code to not use it. I didn't keep track of how long it had run, but it seems it was about a month.

I can post the code if you like.

Uh, yeah you should post the code, since the problem is almost certainly a problem with your code.

Using millis() is fine - if you do the comparisons right, the rollovers are handled fine: millis() - oldTime - when millis rolls over, the subtraction of the old time will also roll over, so you get the right result.

/*   LED Clock
 *   by Dan Griffin 11/15
 *   
 *         12:53
 *   Hour Hour Min Min
 *   ---- ---- --- ---
 *    1   222  55  333
 *    1   222  55  333
 *    1   222  55  333
 *   
 *   Randomly light LEDs depicting the numeric value
 *   of the current time every second.
 *   
 *   Column anodes + (HIGH)
 *   Row anodes -(LOW)
 */

  #include <Wire.h>                                        // RTC Clock.
  #include "RTClib.h"                                      // RTC Clock.
                                                           // LED arrays - [ON/OFF][Row][Column].
  int       intLed[27] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  const int conRow[27] = {2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4,2,3,4};
  const int conCol[27] = {5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,13};
  int       xCount;                                        // Temp counter for how many LEDs are set to ON.
  unsigned long startTime;                                 // Timer to insure 1 second each of ON then OFF.
  long      x;                                             // Temp val for random number generated.
  int       aTime[5] = {1,2,3,4};                          // Array of current time digits (12:34).
  int       iSec = 0;                                      // Temp val for change in seconds.
  RTC_DS1307 RTC;                                          // Create RTC object.

  // ------------------------------------------------------------------------------------------------
void setup() {
  pinMode( 2, OUTPUT);                                     // Rows (3)...
  pinMode( 3, OUTPUT);                                     // Anode (+).
  pinMode( 4, OUTPUT);

  pinMode( 5, OUTPUT);                                     // Colums (9)...
  pinMode( 6, OUTPUT);                                     // Cathode (-).
  pinMode( 7, OUTPUT);
  pinMode( 8, OUTPUT);
  pinMode( 9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

  digitalWrite(2, LOW);                                    // Make sure all LEDs are OFF.
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  for(int i = 5; i < 27; i++) { digitalWrite(i, HIGH); }

  pinMode(16, OUTPUT);                                     // Pin A4 (- GND) for RTC.
  pinMode(17, OUTPUT);                                     // Pin A3 (+ 5v) for RTC.
  analogWrite(16,0);                                       // Set pin A4 LOW.
  analogWrite(17, 255);                                    // Set pin A3 HIGH.

  Serial.begin(9600);                                      // Only used to display error.
  RTC.begin();                                             // Initialize RTC in 24 hour format.
  // RTC.adjust(DateTime(__DATE__, __TIME__));                // Sets RTC to your computer's time at the moment of upload to Uno.
}

  // ------------------------------------------------------------------------------------------------
void loop() {

  DateTime dTime = RTC.now();                              // Get the current time.
  if(dTime.second() != iSec) {
    iSec = dTime.second();                                 // Reset second temp val.
    for(int i = 0; i < 27; i++) { intLed[i] = 0; }         // Zero out the LED array.
    aTime[0] = char(int(dTime.hour() /10));                // Store the time digits.
    aTime[1] = char(int(dTime.hour() -(aTime[0] *10)));
    aTime[2] = char(int(dTime.minute() /10));
    aTime[3] = char(int(dTime.minute() -(aTime[2] *10)));

    // Hours (high).
    xCount = 0;                                            // Reset the counter.
    while(xCount < aTime[0]) {                             // Randomly set LED array to display "tens" of hours.
      x = random(0,3);
      if(intLed[x] == 0) {                                 // If we haven't already set this one...
        intLed[x] = 1;                                     // ...set it to ON.
        xCount++ ;                                         // Keep track of how many have been set.
      }
    }

    // Hours (low).
    xCount = 0;                                            // Reset the counter.
    while(xCount < aTime[1]) {                             // Randomly set LED array to display "ones" of hours.
      x = random(3,12);
      if(intLed[x] == 0) {                                 // If we haven't already set this one...
        intLed[x] = 1;                                     // ...set it to ON.
        xCount++ ;                                         // Keep track of how many have been set.
      }
    }

    // Minutes (high).
    xCount = 0;                                            // Reset the counter.
    while(xCount < aTime[2]) {                             // Randomly set LED array to display "tens" of minutes.
      x = random(12,18);
      if(intLed[x] == 0) {                                 // If we haven't already set this one...
        intLed[x] = 1;                                     // ...set it to ON.
        xCount++ ;                                         // Keep track of how many have been set.
      }
    }

    // Minutes (low).
    xCount = 0;                                            // Reset the counter.
    while(xCount < aTime[3]) {                             // Randomly set LED array to display "ones" of minutes.
      x = random(18,27);
      if(intLed[x] == 0) {                                 // If we haven't already set this one...
        intLed[x] = 1;                                     // ...set it to ON.
        xCount++ ;                                         // Keep track of how many have been set.
      }
    }
  }
  // ------------------------------------------------------ Light LEDs.
  for(int i = 0; i < 27; i++) {
    if(intLed[i] == 1) {                                   // IF we need to light this LED...
      digitalWrite(conRow[i], HIGH);                       // ...ground the row (cathode)...
      digitalWrite(conCol[i], LOW );                       // ...and power the col (anode).
      delay(1);                                            // (0 = dim / 2 = flicker)
      digitalWrite(conRow[i], LOW );                       // Turn it OFF.
      digitalWrite(conCol[i], HIGH);
    }
  }
}

So, if the shutdown problem is in my code, would you mind giving me a clue as to where it might lie?