setup() and loop(): does the board restart itself?

I know that the code in “setup() function” should run ONCE, and the one in “loop() function” should run repeatedly, but I have a question (and maybe a problem) : is it normal that after a while the code in the loop() section stops and the code in the setup() section is executed again?

I made some tests with led lights: at the beginning they’re “LOW”, the I set them “HIGH” in the loop()…but at a certain point they turn off, and back on again and again…

thanks for the help

Please post your sketch but use the code tags to do so ( </> )

It is unusual but it is also possible to force a sketch to run from the start too so without seeing the code then anything is possible.

/* Turn off Led 13*/
void setup() { 
pinMode(13, OUTPUT);//led on pin 13
digitalWrite(13, HIGH);//turn on led
}

void loop() {
delay(3000);//wait 3 seconds
digitalWrite(13, LOW);//turn off led
}

Please show us a diagram (hand drawn is fine) how everything is connected.

The code in reply #2 should not reboot the Arduino.

const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 0;
int led = 2;
long interval = 10000;

void setup() {
  // put your setup code here, to run once:
  for (int x = 2; x < 8; x++) {
    pinMode(x, OUTPUT);  
  }
  pinMode(switchPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentTime = millis();
  if(currentTime - previousTime > interval) {
    previousTime = currentTime;
    digitalWrite(led, HIGH);
    led++;
    if(led == 7){
      
    }
  }
  switchState = digitalRead(switchPin);
  if(switchState != prevSwitchState) {
    for (int x = 2; x < 8; x++) {
      digitalWrite(x, LOW); 
    }
    led = 2;
    previousTime = currentTime;
  }
  prevSwitchState = switchState;
}

the code up here reboots itself several times: my "hourglass" ,as you can see at line 6, counts the minutes, but only three leds (on six) light up, then the board does a reboot...

p.s : I'll post a photo of the connections asap

the connections from post #2

ok: here’s a funny thing:

if in the sketch I include Serial.begin(String) and then in the loop include Serial.print(Other String) my “Hourglass” seems to work fine ONLY IF I open the Serial Monitor on Arduino IDE :

if I launch the program and keep open the window with the Serial Monitor everything’s fine, but as I close it, after a while the boards resets itself

const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 0;
int led = 2;
long interval = 10000;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.print("inizio");
  for (int x = 2; x < 8; x++) {
    pinMode(x, OUTPUT);  
  }
  pinMode(switchPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentTime = millis();
  if(currentTime - previousTime > interval) {
    previousTime = currentTime;
    digitalWrite(led, HIGH);
    Serial.print("Sono passati ");
    int tempoInSec = currentTime / 1000;
    Serial.print(tempoInSec);
    Serial.print(" secondi, ");
    led++;
    if(led == 7){
      
    }
  }
  switchState = digitalRead(switchPin);
  if(switchState != prevSwitchState) {
    for (int x = 2; x < 8; x++) {
      digitalWrite(x, LOW); 
    }
    led = 2;
    previousTime = currentTime;
  }
  prevSwitchState = switchState;
}

I add that the program (I'm talking about the HourGlass) works fine just for about 30s (without Serial.begin(...) and the Serial Monitor opened)

My board: Arduino/Genuino Uno
My Os: Win 10

I think i solved the problem: PC Companion seems to be in conflict with Arduino, causing the reboot of the board. :confused:
now the program runs smoothly, but who knows?!
if you have other suggestions...they're well accepted!!

Is that the SONY thing ?
If it is and you can do without it then kill it.

If not then would you mind posting a direct link to it as there are also some dubious items with that name too.

PC Companion seems to be in conflict with Arduino, causing the reboot of the board.

Various apps that "scan" serial ports can cause the arduino to auto-reset; it's something that the hardware does whenever the port is "opened."

The official way the Arduino Uno expects the auto-reset to be disabled is by cutting a trace and installing a pushbutton to be pressed every time that you want to load new code. Google "Arduino Uno RESET-EN" for directions how to do this.

It seems that adding a 10uF Capacitor between Reset and Gnd also works, which you would then need to remove every time that you want to load new code -> How to keep the arduino uno up on serial connections? - Electrical Engineering Stack Exchange