Reading Input From Serial Monitor In Arduino

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.
 
 
Afterward, plug the Arduino board to your system.
 
 
Afterwards, write the following code to read the input from Serial Monitor and display it as follows:
  1. String name = "";  
  2. String Mobile = "";  
  3. String Address = "";  
  4. String Email = "";  
  5.   
  6. void setup()   
  7. {  
  8.     Serial.begin(9600);  
  9. }  
  10.   
  11. void loop()   
  12. {  
  13.     Serial.println("Enter your name.");  
  14.     while (Serial.available() == 0)   
  15.     { //Wait for user input  }  
  16.     name = Serial.readString(); //Reading the Input string from Serial port.  
  17.     Serial.println("Enter your Moblie No.");  
  18.     while (Serial.available() == 0) {}  
  19.     Mobile = Serial.readString();  
  20.     Serial.println("Enter your Address.");  
  21.     while (Serial.available() == 0) {}  
  22.     Address = Serial.readString();  
  23.     Serial.println("Enter your Email.");  
  24.     while (Serial.available() == 0) {}  
  25.     Email = Serial.readString();  
  26.     Serial.println("-------------------------"); //Showing the details  
  27.     Serial.println("YOUR NAME:" + name);  
  28.     Serial.println("YOUR MOBILE NO:" + Mobile);  
  29.     Serial.println("YOUR ADDRESS:" + Address);  
  30.     Serial.println("YOUR EMAIL:" + Email);  
  31.     Serial.println("Thanks You...");  
  32.     Serial.println("");  
  33.     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.
 
 
Enter all the details and it will show the output like this.
 
 
Hence, in this way, we can read the input from Serial monitor and show it. I hope this will help those who are willing to learn this new technology.