Why do newly uploaded sketches not execute until the serial monitor is opened?

I have only had my Uno a few days, but I am sure it wasn't like this at the start. Now however, it seems, even the example blink program, won't start up until I open the IDE's serial monitor window after I upload the sketch.

If I reset the Uno, or power it up, without the IDE connected, then it works normally. But if I upload a new sketch, the Uno just sits there, until I open the serial monitor - which resets the Uno, and then it starts executing the sketch.

Happens to me too with mega 2560. That's why I opt to use lcd instead for debugging. I'm impatient lol. I'm total noob too. I'll be watching to see what the good guys say. :slight_smile:

noobdude:
Happens to me too with mega 2560. That's why I opt to use lcd instead for debugging. I'm impatient lol. I'm total noob too. I'll be watching to see what the good guys say. :slight_smile:

I have an LCD I can use too, but even without any code trying to write to the serial port (which is why I gave the example of the blink program - it doesn't use the serial port), it still seems to hang. Maybe it's normal - and I never noticed it earlier. Just thought I'd get the experts to set me straight :).

One answer might be, that the sketch is "waiting" to either send data, or receive data,
from the serial monitor.

michinyon:
One answer might be, that the sketch is "waiting" to either send data, or receive data,
from the serial monitor.

I tried to ensure that is not happening, hence why I gave the example of blink program that comes with the IDE. I see nothing in that sketch sending or receiving data.

Here it is to save you having to look for it.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Well if that program is causing your problem, I got no idea. There is nothing that the serial monitor does, or doesn't do, which would cause the problem you describe.

michinyon:
Well if that program is causing your problem, I got no idea. There is nothing that the serial monitor does, or doesn't do, which would cause the problem you describe.

...and yet I am not the only one seeing it happen.

My problem isn't exactly the same. The sketch executes no problem but when I open the serial monitor it restarts the arduino. Sorry dude.

Well I found a fix, but I have no idea why it works.

I have some hardware connected via a shield. A temperature measuring IC, an LCD panel, and a RTC. The culprit was a DS18B20 onwire temperature device. I had it connected to digital pin 4, and it was working when I loaded my sketch that read it's value and displayed it on an LCD panel (that is connected to the IIC bus (along with a DS1307 RTC) using analog pins 4 and 5).

I unplugged things one at a time, until I found that it was the DS18B20 that was causing the odd behaviour of the IDE. I moved it to digital pin 8. Now I can upload a sketch and have the Arduino restart normally again!!!!! Even better, after changing the pin number for the onewire comms - the DS18B20 is working as normal on pin 8.

Keep in mind, the sketch upload problem was happening, even with a sketch that did not access the DS18B20, nor even the digital pin 4 that it was on, for any purpose whatsoever. So what is different between pin 4 and 8 that could cause this strangeness?

noobdude:
My problem isn't exactly the same. The sketch executes no problem but when I open the serial monitor it restarts the arduino. Sorry dude.

That's normal, from what I read, under Mac OS and Linux.

Yeah for sure. It sucks though I can't wait extra 3 -4 seconds hehe. Sometimes its needed for me though.

@OP I'm glad you got it. I don't have explanation unfortunately. :frowning: