3

Code:

void setup() {
  Serial.begin(9600);
  Serial.println("hello");
}

void loop() {
}

Output:

hello
hello

Why does hello print twice?

11
  • 1
    I considered that so I created a new file, restarted the device and Sketch. Still there... Commented Dec 20, 2015 at 8:02
  • 1
    If I open my serial monitor, my arduino sometimes resets twice. I wouldn't worry about this. Commented Dec 20, 2015 at 16:16
  • 1
    @DaveX, I get Hello world Hello world, so it looks like the device is resetting every time, like @Gerben's. Commented Dec 20, 2015 at 17:37
  • 1
    Please edit the question to indicate what type of Arduino you are running this on. They are not all the same with respect to serial port. Commented Dec 21, 2015 at 4:40
  • 1
    Since you get hello world twice, it is also entering into the endless loop twice. Folks are right in that you are seeing two boot-up cycles -- it isn't that the setup is running twice in one poweron/reset cycle. Commented Dec 21, 2015 at 17:14

1 Answer 1

4

It isn't, it's displaying the previous message from when you didn't have the Serial Monitor open yet, plus the new message caused by the Arduino resetting from the Serial Monitor being opened.

If you put a longer message in there you'll probably see the first line get cut off and then the full line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.