Program failure after 5 minute pause

Hi guys, I have uploaded the program below on to a Arduino Uno and it works fine, however, I have uploaded the same program to an Arduino Nano 3.0 Atmel ATmega328 Mini and although it works initially whenever the button is pressed, if left standing for minutes or so it stops working. If the button is pressed Led#1 flashes briefly and nothing else happens. If I disconnect the power and reconnect the power it works fine until it is left standing again. Any help would be greatly appreciated. Many thanks
Dave

[cpp int switchpin = 11; // pin 11 connected to switch int timer = 2000; // The higher the number, the slower the timing. int timer2 = 500; int timer3 = 4000; int thisPin; int allpin2 = 2; int allpin3 = 3; int allpin4 = 4; int allpin5 = 5; int allpin6 = 6; int allpin7 = 7; int allpin8 = 8; void setup() { // set up digital pin read for switch // for loop need this ---> { } for (int thisPin = 2; thisPin < 9; thisPin++) { // this will set pin 2 to pin 8 as output pinMode(thisPin, OUTPUT); } // use a for loop to initialize each pin as an output: pinMode(switchpin, INPUT); } void loop() { // I prefer you hook up like +5 V --- Resistor -- pin 11 --- push button --- GND // when the switch is press ... it will produce a LOW - 0 - 0 V signal if (digitalRead(switchpin) == LOW) { // you forgot the { } delay(100); // debounce time for (int thisPin = 2; thisPin < 9; thisPin++) { // loop from the lowest pin to the highest: // turn the pin on digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); } // end of loop one // loop from the highest pin to the lowest: { // turn the pin on: digitalWrite(allpin2, HIGH); digitalWrite(allpin3, HIGH); digitalWrite(allpin4, HIGH); digitalWrite(allpin5, HIGH); digitalWrite(allpin6, HIGH); digitalWrite(allpin7, HIGH); digitalWrite(allpin8, HIGH); delay(timer3); digitalWrite(allpin2, LOW); digitalWrite(allpin3, LOW); digitalWrite(allpin4, LOW); digitalWrite(allpin5, LOW); digitalWrite(allpin6, LOW); digitalWrite(allpin7, LOW); digitalWrite(allpin8, LOW); } // end of loop 2 } // closing the if () stament } ](https://```cpp int switchpin = 11; // pin 11 connected to switch int timer = 2000; // The higher the number, the slower the timing. int timer2 = 500; int timer3 = 4000; int thisPin; int allpin2 = 2; int allpin3 = 3; int allpin4 = 4; int allpin5 = 5; int allpin6 = 6; int allpin7 = 7; int allpin8 = 8; void setup() { // set up digital pin read for switch // for loop need this ---> { } for (int thisPin = 2; thisPin < 9; thisPin++) { // this will set pin 2 to pin 8 as output pinMode(thisPin, OUTPUT); } // use a for loop to initialize each pin as an output: pinMode(switchpin, INPUT); } void loop() { // I prefer you hook up like +5 V --- Resistor -- pin 11 --- push button --- GND // when the switch is press ... it will produce a LOW - 0 - 0 V signal if (digitalRead(switchpin) == LOW) { // you forgot the { } delay(100); // debounce time for (int thisPin = 2; thisPin < 9; thisPin++) { // loop from the lowest pin to the highest: // turn the pin on digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); } // end of loop one // loop from the highest pin to the lowest: { // turn the pin on: digitalWrite(allpin2, HIGH); digitalWrite(allpin3, HIGH); digitalWrite(allpin4, HIGH); digitalWrite(allpin5, HIGH); digitalWrite(allpin6, HIGH); digitalWrite(allpin7, HIGH); digitalWrite(allpin8, HIGH); delay(timer3); digitalWrite(allpin2, LOW); digitalWrite(allpin3, LOW); digitalWrite(allpin4, LOW); digitalWrite(allpin5, LOW); digitalWrite(allpin6, LOW); digitalWrite(allpin7, LOW); digitalWrite(allpin8, LOW); } // end of loop 2 } // closing the if () stament } ```)

That's not the way to attach your code.

In the Arduino IDE, press CTRL Shift C, then paste the copied sketch to a post.

Hi, @skindog386

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

int switchpin = 11;  // pin 11 connected to switch
int timer = 2000;     // The higher the number, the slower the timing.
int timer2 = 500;
int timer3 = 4000;
int thisPin;
int allpin2 = 2;
int allpin3 = 3;
int allpin4 = 4;
int allpin5 = 5;
int allpin6 = 6;
int allpin7 = 7;
int allpin8 = 8;



void setup()


{



  // set up digital pin read for switch
  // for loop need this ---> { }
  for (int thisPin = 2; thisPin < 9; thisPin++) {

    // this will set pin 2 to pin 8 as output
    pinMode(thisPin, OUTPUT);
  }
  // use a for loop to initialize each pin as an output:
  pinMode(switchpin, INPUT);
}




void loop() {
  // I prefer you hook up like +5 V --- Resistor -- pin 11 --- push button --- GND
  // when the switch is press ... it will produce a LOW - 0 - 0 V signal
  if (digitalRead(switchpin) == LOW) {
    // you forgot the  {   }
    delay(100);  // debounce time
    for (int thisPin = 2; thisPin < 9; thisPin++) {
      // loop from the lowest pin to the highest:
      // turn the pin on
      digitalWrite(thisPin, HIGH);
      delay(timer);
      // turn the pin off:
      digitalWrite(thisPin, LOW);
    }
    // end of loop one
    // loop from the highest pin to the lowest:


    {
      // turn the pin on:
      digitalWrite(allpin2, HIGH);
      digitalWrite(allpin3, HIGH);
      digitalWrite(allpin4, HIGH);
      digitalWrite(allpin5, HIGH);
      digitalWrite(allpin6, HIGH);
      digitalWrite(allpin7, HIGH);
      digitalWrite(allpin8, HIGH);
      delay(timer3);

      digitalWrite(allpin2, LOW);
      digitalWrite(allpin3, LOW);
      digitalWrite(allpin4, LOW);
      digitalWrite(allpin5, LOW);
      digitalWrite(allpin6, LOW);
      digitalWrite(allpin7, LOW);
      digitalWrite(allpin8, LOW);
    }
    // end of loop 2
  }
  // closing the if () statement
}

it might be that your LEDs pull too much current out of the board which makes the voltage-regulator go into thermal shut-down

additionally there is no second loop

int switchpin = 11;  // pin 11 connected to switch
int timer = 2000;     // The higher the number, the slower the timing.
int timer2 = 500;
int timer3 = 4000;
int thisPin;
int allpin2 = 2;
int allpin3 = 3;
int allpin4 = 4;
int allpin5 = 5;
int allpin6 = 6;
int allpin7 = 7;
int allpin8 = 8;

void setup(){
  // set up digital pin read for switch
  // for loop need this ---> { }
  for (int thisPin = 2; thisPin < 9; thisPin++) {

    // this will set pin 2 to pin 8 as output
    pinMode(thisPin, OUTPUT);
  }
  // use a for loop to initialize each pin as an output:
  pinMode(switchpin, INPUT);
}


void loop() {
  // I prefer you hook up like +5 V --- Resistor -- pin 11 --- push button --- GND
  // when the switch is press ... it will produce a LOW - 0 - 0 V signal
  if (digitalRead(switchpin) == LOW) {
    // you forgot the  {   }
    delay(100);  // debounce time
    for (int thisPin = 2; thisPin < 9; thisPin++) {
      // loop from the lowest pin to the highest:
      // turn the pin on
      digitalWrite(thisPin, HIGH);
      delay(timer);
      // turn the pin off:
      digitalWrite(thisPin, LOW);
    }
    // end of loop one
    // loop from the highest pin to the lowest:

    { // opening brace without any loop-structure so there is no second loop
      // turn the pin on:
      digitalWrite(allpin2, HIGH);
      digitalWrite(allpin3, HIGH);
      digitalWrite(allpin4, HIGH);
      digitalWrite(allpin5, HIGH);
      digitalWrite(allpin6, HIGH);
      digitalWrite(allpin7, HIGH);
      digitalWrite(allpin8, HIGH);
      delay(timer3);

      digitalWrite(allpin2, LOW);
      digitalWrite(allpin3, LOW);
      digitalWrite(allpin4, LOW);
      digitalWrite(allpin5, LOW);
      digitalWrite(allpin6, LOW);
      digitalWrite(allpin7, LOW);
      digitalWrite(allpin8, LOW);
    }
    // end of loop 2
  }
  // closing the if () statement
}

Hi StefanL38. Thanks for your input. I dont need a second loop as I have the button press to repeat the first loop as necessary. I dont think it will be pulling too much current because if I keep pressing the button at the end of the loop it will repeat the loop as many times as I want. It is only if I dont press the button for approx 5 mins then pressing the button just makes Led 1 illuminate for a quick flash then nothing else. It is very strange

Hi Tom, circuit diag as requested. Hope this helps
Thanks

Hi,
Thanks for the schematic.

Can you place in your code the "Blink without delay" example code to make the onboard LED flash.
That way we can see if you have a code stops.

Do you have a DMM.
When it faults measure the 5V pin of the Nano before you reset it. This will check if you have a serious overload.
Check the 3V3 pin as well.

Thanks.. Tom.. :+1: :coffee::australia:

Thanks again Tom. I connected a 9v battery to VIN and all is good now. I think the USB from computor was not good enough. Thanks for your help

Thanks to everybody that helped. I have now solved the problem by using a 9V battery connected to VIN which was my intent anyway.