Arduino Program Reset Bug
<p>I'm using an Arduino Uno and ATMega328P to simply control a few LEDs with switches controlled by the user.  However, after about 56 iterations through my main loop (or ~16 seconds) my program resets.  I suspect it has something to do with the Watchdog timer, but even with it disabled via wtd_disable(); in my setup, the problem persists.  The program does enter a loop that it can only exit if the user flips a switch.  Any suggestions?</p>

<pre><code>//Don't worry, I have all necessary libraries and variables set up.

void setup()
{ 
  Serial.begin(9600);  // start serial for output
  Serial.println(i2c_init());

  wdt_disable();

  //pinMode(22,INPUT_PULLUP);
  //pinMode(23,INPUT_PULLUP);
  pinMode(wakePin, INPUT);
  pinMode(ACPin, INPUT);
  pinMode(PowerPin, INPUT);

  pinMode(PowerLED, OUTPUT);
  pinMode(ACLED, OUTPUT);
  pinMode(Battery1LED, OUTPUT);
  pinMode(Battery2LED, OUTPUT);
  pinMode(WifiLED, OUTPUT);
  pinMode(TesterLED, OUTPUT);
  pinMode(EnableLED, OUTPUT);
  attachInterrupt(0, wakeUpNow, LOW);


}        

void loop()
{

  digitalWrite(PowerLED, LOW);
 // digitalWrite(ACLED, LOW);    Exclude AC Power LED
  digitalWrite(Battery1LED, LOW);
  digitalWrite(Battery2LED, LOW);
  digitalWrite(WifiLED, LOW);
  digitalWrite(TesterLED, LOW);
  digitalWrite(EnableLED, LOW);

  Enable = 0;

  Serial.println("Reset Complete");


  int ACPower = digitalRead(ACPin);
  digitalWrite(ACLED, ACPower);

  int v1 = fetchWord(deviceAddress1, VOLTAGE);
  int v2 = fetchWord(deviceAddress2, VOLTAGE);
  int BatteryVoltage = max(v1,v2);
  Serial.print("Highest Battery Voltage: ");
  Serial.println(BatteryVoltage);

  delay(250);

  if((BatteryVoltage &gt;= 7000) | (ACPower == 1)){
    int PowerOK = digitalRead(PowerPin);
    if (PowerOK == 0){
      loop();
    }else {
      bulk();

    }
  }else{
    loop();
  }

}

//This is the main part of my code that is constantly looped through,
//and after 16 seconds, the program resets, going back to loop()

void bulk()
{

  Enable = 1;
  digitalWrite(EnableLED, HIGH);

  int ACPower = digitalRead(ACPin);
  digitalWrite(ACLED, ACPower);

  //int Battery1State = BatteryState(deviceAddress1);
  int Battery1State = 2;  // Simulating low battery
  switch (Battery1State){
    case 1:
      digitalWrite(Battery1LED, HIGH);
      break;
    case 2:   //I can't run parallel code to control the blinking LED, 
//so I toggle the LED every pass through.  Case 2 blinks slowly
    if(i &gt;= 4){
      toggleLED(Battery1LED);
      i = 0;
    } else {
      i++;
    }
      break;
    case 3:  //case 3 blinks quickly
    toggleLED(Battery1LED);
        break;

  }
  int Battery2State = 3;  // simulating a very low battery
  switch (Battery2State){
    case 1:
      digitalWrite(Battery2LED, HIGH);
      break;
    case 2:
    if(j &gt;= 4){
      toggleLED(Battery2LED);
      j = 0;
    } else {
      j++;
    }
      break;
    case 3:
    toggleLED(Battery2LED);
        break;

  }




  buttonState = digitalRead(wakePin);  //button is HIGH by default
  if(buttonState == HIGH){


    Serial.println(count);
    if(count == 0){
      starttime = millis();
    } else if (count == 54){
      endtime = millis();
      runtime = endtime - starttime;
      Serial.print("System Run Time: ");
      Serial.println(runtime);
    }

    count++;
    int PowerOK = digitalRead(PowerPin);

    digitalWrite(PowerLED, PowerOK);
    delay(250);
//Repeat this code if power switch is on, restart if power is turned off

    if(PowerOK == 0){

      loop();    
    }else {

      bulk();
    }
</code></pre>