Arduino unresponsive after a long time

Hey guys. I’m having a problem where my arduino stops becoming responsive after a long time of being “off”. I’m powering it with an atx power supply.
Wiring:
I have the 5vsb wire connected to the + power strip on my breadboard. I have the 5v pin on the arduino and the vcc of my bluetooth module connected to that same strip. I’m also powering the arduino with the 12v rail. I have the enable wire of the power supply connected to pin 7. The enable is active LOW so I just toggle that with serial input.

My intention is that I can turn the main power supply off with a serial command and still keep the Bluetooth module powered so I can turn it back on. When pin 7 is LOW the enable is grounded and the power supply turns on. When it is HIGH everything is off besides the bluetooth and arduino.

This works fine for less than a couple hours. I can toggle it on and off as often as I want and I’ve never run into an error. If the main power is off for a long period of time; when I send the on signal the arduino sents pin 7 to LOW and the power supply fans turn on. After that none of the other functions work. It is completely unresponsive to any other Serial input but it is still on and the bluetooth is on.

Here is a snippet of the code I’m using to do this:
case 123:
while(!Serial.available());
break;

if(Serial.available()){
char inputChar;
inputChar = Serial.read();
// Serial.println(inputChar);
Serial.read();
if(inputChar==111)//o for on
{
on = 1;
int randNum = random(3);
switch(randNum){//random clock colors on startup
case 0:
mode =20;
break;
case 1:
mode = 21;
break;
case 2:
mode = 22;
break;
}
digitalWrite(7,LOW);
}
else if(inputChar==79)//O for off
{
digitalWrite(7,HIGH);
on = 0;
mode =123;

}
else if(on ==1){
stuff…
}

The whole code is here: http://pastebin.com/nzYPh2ac

I can’t for the life of me figure out what is causing this because the program doesnt respond to anything but the on button while it is “off” and like I said the only thing that causes it to break is just being on for a long time. Once I reset the power to the arduino it functions normally again. I would really appreciate some help.

ledstripfix.ino (81 KB)

Post the full code as an attachment or in code tags (The # symbol above the smiley face) [ code ]...[/ code ]

(deleted)

The whole code is over 2000 lines so I've added it in a paste bin at the end and as an attatchment

(deleted)

Alright, did that as well.

O_O,

Length is not really an issue, but no spacing, why...? This will take some time to go through.

Do you mean spacing in the loop and setup? I know that the functions that are called in the different modes work so theres no need to through all of those.

edit: By the way I just recently added this part to the beginning of the for loop as a psuedo fix: if(on == 0&& millis()-resetTime>=5000000){ digitalWrite(7,LOW); delay(1000); digitalWrite(7,HIGH); }

We have to be able to read what were looking at.

A lot of this is very eye straining,

Some code here Some code here Some code here Some code here Some code here Some code here Some code here Some code here Some code here

I just uploaded a new sketch that I spaced out a bit.

Do you ever see "Enter Parameters" ?

Generally yes, after being on for a long time no.

Since you have my whole code you can see that when I turn the arduino on it is supposed to go into mode 20,21, or 22 when it is turned on. This normally displays a clock on LEDS that I have wired up. When it enters the unresponsive state literally nothing happens except for the LOW signal being sent. The lights never turn on, nothing functions as it should.

There might be a memory leak somewhere, but I'm not certain until I can get home and do some tests.

Is there anything I could possibly do? I thought that if there is a memory leak it wouldn't even accept the on command. Also I've left it on over night in "on" mode and it never became unresponsive if that is of any help. Really appreciate your assistance.

There is a huge amount of code there that presumably has nothing to do with the Arduino turning on and off. I don't pretend to understand your description of how the Arduino will be turned on and off but I suggest that you write a minimal sketch that does as little as possible while supporting being turned on and off in the way your real sketch will be turned on and off. Add a simple timer to make an LED flash in a recognisable pattern which tells you what the Arduino is doing. See whether it produces the same problem. This will tell you whether there is a system design issue or just a software bug.

I changed a few things with this part.

if(Serial.available()) // ← Made just IF, not ELSE IF
{
char inputChar;
inputChar = Serial.read();
// Serial.println(inputChar);
Serial.read();
if(inputChar == ‘o’)//o for on ← Made them actual chars
{
on = 1;
int randNum = random(3);
switch(randNum)
{//random clock colors on startup
case 0:
mode =20;
break;
case 1:
mode = 21;
break;
case 2:
mode = 22;
break;
}
digitalWrite(7,LOW);
}
else if(inputChar == ‘O’)//O for off ← same here
{
digitalWrite(7,HIGH);
on = 0;
mode =123;
resetTime = millis();
}
if(on ==1)
{
Serial.println(“I am Here”); // ← added this to see where the code was at
if(inputChar==104)//h for help
{
startup();
}
else if (inputChar ==108)//l for list of modes
{
modeList();
}
else if (inputChar ==112)//p for pretty colors
{
colors();
}
else
{
Serial.println(“Enter Parameters”);
while(!Serial.available())
{ }
switch(inputChar)
{
case 109://m for mode
mode = Serial.parseInt();
// Serial.println(mode);
break;

case 98://b for background
backR=brightnessLimit(Serial.parseInt());
backG=brightnessLimit(Serial.parseInt());
backB=brightnessLimit(Serial.parseInt());
// Serial.print((backR));
// Serial.print(F("."));
// Serial.print((backG));
// Serial.print(F("."));
// Serial.println((backB));
break;

case 99://c for color
globalR=brightnessLimit(Serial.parseInt());
globalG=brightnessLimit(Serial.parseInt());
globalB=brightnessLimit(Serial.parseInt());
// Serial.print((globalR));
// Serial.print(F("."));
// Serial.print((globalG));
// Serial.print(F("."));
// Serial.println((globalB));
break;

case 100://d for delay
myDelay = Serial.parseInt();
// Serial.println(myDelay);
break;

case 115://s for set display message
currentMessage = Serial.parseInt();
// Serial.println(myDelay);
break;

case 105://i for intensity of light
maxBrightness = Serial.parseInt();
// Serial.println(maxBrightness);
break;

case 122://z for background brightness
backGroundBrightness = Serial.parseInt();
break;

default: break; // ← Add a default case
}
Serial.read();
}
}

I'll add the changes and see what happens.