Introduction
Here, I will describe how to read the input from Serial Monitor and show the input. For this, we require the Arduino IDE for writing the program. Here, I have my IDE. In case you don't have the IDE, you can download it from the following Link.
For writing the program, go to FILE-> NEW, after which, you will get the following screen.


Afterwards, write the following code to read the input from Serial Monitor and display it as follows:
- String name = "";
- String Mobile = "";
- String Address = "";
- String Email = "";
- void setup()
- {
- Serial.begin(9600);
- }
- void loop()
- {
- Serial.println("Enter your name.");
- while (Serial.available() == 0)
- { //Wait for user input }
- name = Serial.readString(); //Reading the Input string from Serial port.
- Serial.println("Enter your Moblie No.");
- while (Serial.available() == 0) {}
- Mobile = Serial.readString();
- Serial.println("Enter your Address.");
- while (Serial.available() == 0) {}
- Address = Serial.readString();
- Serial.println("Enter your Email.");
- while (Serial.available() == 0) {}
- Email = Serial.readString();
- Serial.println("-------------------------"); //Showing the details
- Serial.println("YOUR NAME:" + name);
- Serial.println("YOUR MOBILE NO:" + Mobile);
- Serial.println("YOUR ADDRESS:" + Address);
- Serial.println("YOUR EMAIL:" + Email);
- Serial.println("Thanks You...");
- Serial.println("");
- while (Serial.available() == 0) {}
- }
Here, I have explained which function is used. Now set the Serial port to "COM5".
Afterward, upload the code by clicking the Upload button, using the Upload button.


Now Open the serial port and check.



James HollowayPosted Sep 4, 2020, 10:33 AM
Hi. I really like this code as a good example. May I point out there was an error? I copied and pasted the entire code and got this error message: 'void loop()':sketch_sep04b:34:1: error: expected '}' at end of input } ^ exit status 1 expected '}' at end of input I was able to fix it by moving the comment " //Wait for user input" to the other side of the bracket. I hope this helps others.
Saineshwar BageriPosted Jul 4, 2016, 1:08 PM
Nice one
Vignesh ManiPosted Jul 4, 2016, 11:07 AM
Nice
kalu singh raoPosted Jul 4, 2016, 1:37 AM
Nice...
RajaPosted Jul 4, 2016, 12:35 AM
Good One..