title: Why does delay() cause my arduino to reset?
body: <p>I am using an Arduino Uno, connected to a USB shield, a RFID shield(adafruit PN532), an LCD, EEPROM(24AA256) and a RTC module(DS1307). I will not post my code here because it is too large and it is separated in multiple files.</p>
  
  <p>In my program, I realize that if my programs enters a certain functions, after entering function after function, if I use a delay() at the end of the function I am currently in, the arduino resets. An example of what I mean is below.</p>
  
  <pre><code>void a() { b(); }
  void b() { c(); }
  void c() { d(); }
  void d()
  {
    lcd_string("Testing", 0x80);
    delay(2000);      &lt;---- Arduino resets at the delay here
  }
  </code></pre>
  
  <p>At first, I thought it was because my  dynamic memory was at 80%, and when I compiled, they said the Arduino might have some stability issues. So I modified my code such that my dynamic memory is now 57%. Problem still exist.</p>
  
  <p>I thought maybe the delay() function has some overflow or something, so I tried replacing the delay with the following code.</p>
  
  <pre><code>unsigned long timing;
  
  timing = millis();
  timing += 2000;
  while(millis() &lt; timing);
  </code></pre>
  
  <p>The Arduino still resets.</p>
  
  <p>Next, I thought maybe because my arduino is connected to my PC, some serial pin might have been causing the reset, so I used an external Power to power up the arduino and disconnected the USB. The arduino still resets.</p>
  
  <p>Next, I thought maybe Timer1 might have been crashing with the delay() function, although the delay function uses Timer0 so I disabled my Timer1 . The arduino still resets.</p>
  
  <p>Is there any other possibilities that I am missing out? My program storage space is at 69% which I believe shouldn't be an issue.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here is my code for Timer1 ISR</p>
  
  <pre><code>ISR(TIMER1_OVF_vect)
  {
    TCCR1A = 0;
    TCCR1B = 0;
    TCNT1  = 0;
    OCR1A = 34286;// = (16*10^6) / (1*1024) - 1 (must be &lt;65536)
    TCCR1B |= (1 &lt;&lt; CS12);  
    // enable timer compare interrupt
   TIMSK1 |= (1 &lt;&lt; TOIE1);
   triggered = 1;
  }
  </code></pre>
  
  <p>Any other interrupt of flags used are in the library header files.
  I am using the following external libraries<BR>
  USB Host shield library 2.0<BR>
  Adafruit PN532 master</p>