Serial Monitor repeats println

the code is intended to obtain user input through the Serial Monitor.
the msg prints twice when code is run , there are no error messages, User input is accepted.

void loop() {
  // put your main code here, to run repeatedly:
  while  (Serial.available() == 0 ){

you just don't do anything if there is no user input and then the loop, loops... so the Serial.println(msg); is done again and again

I would suggest to study Serial Input Basics

Your sketch is incomplete.

I suspect you aren't handling line ending characters correctly.

Take a look at the examples in
Arduino Serial – Reading/Parsing
for how to read from Serial, and trim() off and line endings.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.