Arduino

How to display serial input from computer to LCD using Arduino Uno

There are multiple ways through which we can give inputs to the Arduino program. Similarly, these inputs can also be displayed using different methods. The inputs can be given by interfacing some external devices like keypads or any sensor whose value can be manually changed or by using the serial monitor of Arduino IDE.

Moreover, the inputs can be displayed using the serial monitor as well as interfacing the display modules with Arduino. This discourse explains giving input to the Arduino program using the serial monitor and then displaying that input on the liquid crystal display (LCD) briefly.

Serial monitor of Arduino IDE

Arduino IDE is the software that bridges the communication between the computer and the Arduino boards using a USB cable. This software is mainly used to upload the Arduino program into the Arduino board. Moreover, this software has a serial monitor which displays the outputs and inputs of the Arduino program when it is compiled.

you can open the serial monitor by clicking on the blue icon on the top right on the Arduino IDE. After clicking a tab named serial monitor will be opened at the bottom of the ArduinoIDE.

To enter the input on the serial monitor you can enter the input by writing it in the grey bar that is highlighted in red in the figure given below

Text Description automatically generated

The figure above shows how the serial monitor can be used in the Arduino IDE.

How to display serial input from computer to LCD

To give a clear idea of how we can give the input to Arduino using the serial monitor we have given an example. The components used in this example are:

  • Arduino Uno
  • Jumper wires
  • Liquid crystal display
  • Arduino IDE

The schematic for the circuit is:

Diagram, schematic Description automatically generated

Hardware Assembly

To connect the circuit we have positioned all the components on the breadboard first and after that using connecting wires we interface the LCD with Arduino.

We have given the image for the hardware assembly of the project in which the purple wires are connecting the data pins of the LCD with Arduino. Whereas the yellow wire connected to the output of the potentiometer is given to the liquid crystal display for its brightness control. Furthermore, the gray pins are connecting the RS and E pins of the LCD to the Arduino Uno.

We have used the top two pin layers of the breadboard , one for the 5 volts and the other for the ground, to connect the LCD and potentiometer with voltage supply.

Arduino code for displaying the serial input on LCD

The Arduino code compiled for displaying the serial input on the LCD is given as:

#include <LiquidCrystal.h>// library for LCD

LiquidCrystallcd(12, 11, 5, 4, 3, 2);// Arduino pin for the LCD
void setup() {
Serial.begin(9600);// initializing the Serial communication
lcd.begin(16,2);// initializing the dimensions of LCD
Serial.println("Enter a website");// data to be printed
lcd.setCursor(0,0);// setting the place for the data on LCD
lcd.print("Enter a website");// data to be printed
  }
char a_byte = 0;// defining a character data for a variable
String a_str = "";// creating a string having space

void loop() {
  if (Serial.available() > 0) { /*checking if any input is given on the Serial monitor*/    
a_byte = Serial.read(); /*read if there is any input and save it in the character data type variable*/    

    if (a_byte != '\n') {/*to display the data on the next line one line space is added to the string */
a_str += a_byte;
    }
    else {
Serial.println(a_str); // print the string on the serial monitor
lcd.setCursor(0,1);// setting the place for the data
lcd.print(a_str);// print the data on the LCD
a_str = "";
Serial.println("");// printing the string having space
    }
  }  
}

The Arduino program takes a character input from the serial monitor and then this input is displayed on the LCD interfaced with Arduino. We have used the Serial.available() function to read the inputs from the serial monitor which only reads the number of bytes that are available for reading.

After the program finds that there is data available the Serial.read() function is used in the Arduino code for reading the data stored in the number of bytes. This is the actual data, or we can say the input given from the user on the serial monitor.

The data read by the Arduino is then given to the lcd.print() function so that it can display the data on the LCD. Furthermore, there are two if conditions that are used: the first condition is used to check if there is any data on the bytes to read. The second condition sets the display position of the data that is given as an input in such a way that if the data is not coming on the first row of the display module then add a space of the next line in the string variable to move it to the next line. If not then just display the data on the LCD.

Hardware output of the Arduino code for displaying serial input on LCD

The Arduino code is asking to enter the name of any website in the serial monitor as shown in the figure below:

Graphical user interface, text, application Description automatically generated

The same is also displayed on the LCD:
A circuit board with wires Description automatically generated with low confidence

Now we have given the input to Arduino in the serial monitor as written the gray color row:

Graphical user interface, text, application Description automatically generated

Then by pressing Ctrl+Enter to enter the input and the input will be displayed on the LCD.

The input is displayed on the LCD when it is entered from the serial monitor and can be seen in the image posted below:

A picture containing electronics, circuit Description automatically generated

The input is also displayed on the serial monitor as well:

Graphical user interface, text, application Description automatically generated

Conclusion

In the Arduino programming we can give the inputs to the Arduino board using the Arduino IDE. The Arduino IDE uses its serial monitor for displaying the outputs of the Arduino and also uses it for giving the inputs to the Arduino board. To give inputs using the serial monitor there are mainly two functions used that are Serial.available() and Serial.read() function. In this write-up the serial inputs are taken and then displayed on the liquid crystal display (LCD).

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.