Why does my Serial Monitor print per character to the next line?

Hello....

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
    if (Serial.available ()){
        Serial.print ((char) Serial.read ());
        Serial.print ("\n");
    }
}

i'm trrying to make a simple program that will print whatever i input to the Serial Monitor, i want that each time i press enter, Serial Monitor print whatever words i type into to a single line, than make a new line, but i can't seem to make it work, without the Serial.print ("\n");, it would just continue showing character i input in a single, but with it, it gives a new line to every character, for example i input "test", it send me

t
e
s
t

what i would like to want is it "to only make a new line per words i everytime i press enter", not every character i typed, must be something wrong in my code

any help would be appreciated

I don't think the serial monitor sends what you have typed until you click the SEND button.

It will then send what you have typed along with any line ending characters you have selected in the drop down at the bottom of the serial monitor window.

you have this in the while loop, for each character your read

so no wonder you have a new line per character.

depending on how you configured your Serial monitor, CR, LF or both can be sent when you press enter on your keyboard. Those characters will thus arrive as well into your arduino

so if you send a new line, then you can just do

void setup() {
  Serial.begin(9600);
}

void loop() {
    if (Serial.available ())  Serial.write(Serial.read());
}

and you'll see the text as it is being sent

PS/ don't use 9600, it's so last millenium... use at least 115200 bauds it will work fine.

thanks for the info on using 115200

i think you missed the point i was trying to say, now it will continue every words i sent in a single line, so if i typed "test" :arrow_forward: send, then "Hello" :arrow_forward: send, the "Hello" will appear on the same line as "test", like:

testHello

while the previous case is that it will appear:

t
e
s
t
H
e
l
l
o

I would want it to be :

test
hello

Thank you...

sorry, what i meant by "enter" is send

What line ending setting do you have - see bottom of serial monitor window. I recall the options are something like: None, Line Feed, Carriage Return or CR+LF.

ahhh...it was "No Line Ending", my bad :cry: ... thank you very much, i'm new, though it was on the code itself

Changed it to Newline

That was the point you missed here

Hi everybody....i'm new to the forum and new to programming in Arduino IDE, i would like to make a simple program in Arduino Uno, which will print whatever we type in Serial Monitor (Integer or character) on to the window in Serial Monitor directly. I'm connecting my Arduino Uno to my PC through USB Cable, i'm new and just want to tweak arround the Arduino IDE

Any help would be appreciated

    if (Serial.available ())
        Serial.print (Serial.read ());

don't forget the Serial.begin (9600); and set the Serial monitor to the same bit rate

Welcome.

You might find this useful: Serial Input Basics - updated

Thanks for the quick reply...

however when i tried to type a number or character, it just gives me a number of arround 50, this is my code :

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
    if (Serial.available ())
        Serial.print (Serial.read ());
}

For example, if i input the number "1", Serial Monitor gives me a value of 49, then the number "2", with a reply of "50"...and so forth

What i want is when i type "1", Serial monitor gives me an answer of "1", when i type "a", gives me an "a"

i've match the Serial Monitor to the same bitrate, btw

sorry (always need to test, even the simplest of programs)

it was printing the decimal ASCII value

following "casts" the value as a "char" forcing the print to print it as an ASCII char

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
    if (Serial.available ())
        Serial.print ((char) Serial.read ());
}

Okay...much thanks for the help :slight_smile:

Your two topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.