Reading Input From Serial Monitor In Arduino

Here, I will describe how to read the input from Serial Monitor and show the input. For this, we require 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, 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.     Serial.begin(9600);  
  8.    
  9. }  
  10.   
  11.   
  12. void loop() {  
  13.     
  14.    Serial.println("Enter your name.");  
  15.    
  16.   while (Serial.available()==0)  
  17.   {                                       //Wait for user input  
  18.     
  19.   }  
  20.    name=Serial.readString();  //Reading the Input string from Serial port.
  21.   
  22.       
  23. Serial.println("Enter your Moblie No.");  
  24.    
  25.   while(Serial.available()==0)  
  26.   {  
  27.       
  28.   }  
  29.    Mobile=Serial.readString();  
  30.    
  31.     
  32.    Serial.println("Enter your Address.");  
  33.    while(Serial.available()==0)  
  34.   {  
  35.       
  36.   }  
  37.   Address=Serial.readString();  
  38.    Serial.println("Enter your Email.");  
  39.     while(Serial.available()==0)  
  40.   {  
  41.       
  42.   }  
  43.   Email=Serial.readString();  
  44.     
  45.   Serial.println("-------------------------");  //Showing the details
  46.   Serial.println("YOUR NAME:"+name);  
  47.   Serial.println("YOUR MOBILE NO:"+Mobile);  
  48.   Serial.println("YOUR ADDRESS:"+Address);  
  49.   Serial.println("YOUR EMAIL:"+Email);  
  50.    Serial.println("Thanks You...");  
  51.    Serial.println("");  
  52.     while(Serial.available()==0)  
  53.   {  
  54.       
  55. }  
Here, I have explained which function is used. Now set the Serial port to "COM5".



Afterwards, 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.

Up Next
    Ebook Download
    View all
    Learn
    View all