Author's Picture
Author: Joel Gray Published: 30 August 2020 Read Time: ~4 minutes

Display Text on LCD using Arduino

How to Display Text on a 16×2 LCD Screen

Here we are going to use a 16×2 LCD screen and our Arduino Microcontroller to display some text.

I’m going to give two examples of code to try, one show how to display some static text and the other shows how to change the text over a certain set time.

Always try to be creative and do a little but more than what the tutorial shows you. Play with the code and maybe add another few components, this will help you more than just copying the code.

  • Arduino with LCD
  • Arduino with LCD
Links to what you’ll need:

1x Breadboard

1x Arduino Uno

1x 16×2 LCD

9x Jumper Wires

1x USB-A Cable

How do I start?

The first thing to do is to take a look at our photos above to see how the circuit is constructed, and then have a go building it yourself! Hint: Use the circuit diagram when building it, it’s there for a reason.

We use a potentiometer to control the contrast of the LCD screen. The left pin of the potentiometer is the VCC in the middle pin is Voltage Out and the right pin is the Ground pin.

Connect the positive rail of the breadboard to the 5V pin on the Arduino, and connect the ground rail to the GND pin.

Video below shows Arduino running the second example code, where the text appears after a given time period.

A quick summary of the circuit can be seen below:

LCD Pin VSS > Ground

LCD Pin VDD > +5V

LCD Pin V0 > V Out from Pot

LCD Pin RS > Pin 9

LCD Pin RW > Ground

LCD Pin E > Pin 8

LCD Pin D4 > Pin 5

LCD Pin D5 > Pin 4

LCD Pin D6 > Pin 3

LCD Pin D7 > Pin 2

LCD Light + > 5V

LCD Light – > Ground

Pot Vcc > 5V

Pot Ground > Ground


Let’s run through what the code is doing

The following code is used to implement the project by uploading it to the Arduino Microcontroller.

We use #include <Library.h> to include the required libraries in the project. Then we assign the Arduino pins to their respective variables named after the pin on the LCD to which they are connected . We then pass these variables into the Liquid Crystal library function.

Inside the Setup function we use the lcd.begin() library specific function to allow the LCD screen to start receiving data and to operate properly. If we want to show the same text at all times we will enter our lcd.print() functions in the setup function also.

Then inside the main loop function we include nothing IF we are showing the same text at all times. However if we want to alter our text then we will use the lcd.print() function here and using the delay() function we can change the text after a certain period of time.

Check out the information given on Arduino documentation to learn more.


Now open the Arduino IDE and copy the code below

If you don’t know how to do this, check out our Arduino Sketch set up tutorials and youtube videos.

  
#include <LiquidCrystal.h> //including library for LCD (16,2) 
const int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //LCD pinout declaration
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // put your setup code here, to run once:
  
  lcd.begin(16,2);      //begin LCD screen, defining the size of the screen

  lcd.setCursor(0,0);                  //set LCD cursor to start of 1st line to get ready to print temperature
  lcd.print("Welcome :)");                  //print the aforementioned data from the array to the LCD

  lcd.setCursor(0,1);                 //set LCD cursor to start of 2nd line to get ready to print humidity
  lcd.print("www.graycode.ie");        //print the aforementioned data from the array to the LCD
}

void loop() {
  // No code to be repeated

}
 
/*
  created 28/08/2020
  by Joel Gray

  graycode.ie
*/

  
#include <LiquidCrystal.h> //including library for LCD (16,2) 
const int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //LCD pinout declaration
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);      //begin LCD screen, defining the size of the screen
}

void loop() {
  // put your main code here, to run repeatedly:
        lcd.setCursor(0,0);                  //set LCD cursor to start of 1st line to get ready to print temperature
        lcd.print("Welcome :)");                  //print the aforementioned data from the array to the LCD
        
        delay(5000);
        lcd.setCursor(0,1);                 //set LCD cursor to start of 2nd line to get ready to print humidity
        lcd.print("www.graycode.ie");        //print the aforementioned data from the array to the LCD
        
        delay(5000);
        lcd.clear();
}

/*
  created 28/08/2020
  by Joel Gray

  graycode.ie
*/