Void Setup - Serial.Begin (runs everytime I open serial port?)

Hi Guys,

So I am a little confused by some code that I have pulling out temperature readings and printing them in the serial port.

Definition of setup;
The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.

void setup() /*----( SETUP: RUNS ONCE )----*/
{
/*-(start serial port to see results )-*/
delay(1000);
Serial.begin(9600);
Serial.println("YourDuino.com: Electronic Brick Test Program");
Serial.println("Temperature Sensor DS18B20");
delay(1000);

/*-( Start up the DallasTemperature library )-*/
sensors.begin();
}/*--(end setup )---*/

So why does this set of commands run every time I open the serial port? I can understand why the following temperature readings appear as they are in the loop structure.

What do you mean "open the serial port"?

If you open the Serial Monitor, it resets the Arduino.

Bingo :slight_smile: Thanks Nick, that neatly explains that for me. just needed to make sure I wasn’t failing to understand the setup structure.

Appreciate the lightning fast response :slight_smile:

[quote author=Nick Gammon link=msg=2342630 date=1438679752] What do you mean "open the serial port"?

If you open the Serial Monitor, it resets the Arduino. [/quote]on most, but not all Arduino boards. From the description of the problem the OP does not have one of the exceptions.

Personally I prefer the reset and have previously been confused when using a Leonardo where opening the Serial monitor does not reset the board.