LCD (Liquid Crystal Display)

LCD (Liquid Crystal Display) © GPL3+

Want to display text? Here is your component!

  • 30,778 views
  • 41 comments
  • 101 respects

Components and supplies

Apps and online services

About this project

Have you ever wanted to display text on your project? Well here is a tutorial on how to hook-up and use a 16x2 LCD (Liquid Crystal Display)!

Once you gather the materials which are highlighted in the Components and Supplies section, use the picture of the circuit in the Schematics section as a reference to build the basic connection to the LCD. Please make sure you put the wires into the correct spot/port. At this point you are all set for programming the LCD!


#import <LiquidCrystal.h>

Start off the program by including the LCD library. This library should be already downloaded to the Arduino IDE. If for some reason it isn't, go to the Sketch menu >> Include Library >> Library Manager. In the top right text box, type in LiquidCrystal then look for the LiquidCrystal Library. Once you find the library click on it, select the latest version and hit install.

Initializing the LCD library is like initializing the servo motor library:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

the numbers are the port numbers that are connected to the pins on the LCD from left to right (LCD is right-side-up).

Begin the LCD by using the code bellow:

lcd.begin(16,2); //16,2 for 16x2 LCD screen

In my case I am using a 16x2 LCD. You can find out the size of your LCD by counting how many boxes there are on the screen (the boxes, not pixels):

.

Here are three basic functions (in code) for the LCD:

#1

lcd.print("Hello");

The code above prints the word "Hello" on the LCD. "Hello" will appear at where the cursor is located. Be sure you check the output string you want is within the ranges of your LCD (16x2 can only have 16 character strings per row).

#2

lcd.setCursor(0,0);

This piece of code will set the cursor to the first row and first column of the LCD.  LCD cursors are zero-indexed so zero would be the first number and one would be the second.

#3

lcd.clear();

It's pretty self explanatory, this line will clear the LCD screen and set the cursor to 0,0.


Please leave feed back on this tutorial, Thank you!


Bellow is a demo video with what you can do with the LCD setup provided in the Schematic section:


Code

LCD SetupArduino
Main Code with Comments.
#include <LiquidCrystal.h> //Import the LCD library
//Include^
//Init
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); /*Initialize the LCD and
                                        tell it which pins is
                                        to be used for communicating*/

//Global Var
#define contra 9 //Define the pin that controls the contrast of the screen
#define bri 10 //Define the pin the controls the brightness of the screen
//Both pins are PWM so you can analogWrite to them and have them output a variable value


void setup() {//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // put your setup code here, to run once:
  lcd.begin(16, 2); //Tell the LCD that it is a 16x2 LCD
  pinMode(contra, OUTPUT); //set pin 9 to OUTPUT
  pinMode(bri, OUTPUT); //Set pin 10 to OUTPUT
  //pinMode-ing OUTPUT makes the specified pin output power
  digitalWrite(contra, LOW); /*outputs no power to the contrast pin.
                            this lets you see the words*/
  analogWrite(bri, 255); //Outputs full power to the screen brightness LED
}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void loop() {//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // put your main code here, to run repeatedly:
  lcd.print(" Hello, World!!"); //Output " Hello, World!!" on the first line of the LCD
  lcd.setCursor(0, 1); /*Set the (invisible) cursor on the first place second row of the LCD.
                        Cursor values are 0-indexed, 0 would the be the first place.
                        The cursor coordinates are X,Y coordinates.*/
  lcd.print("16x2 LCD Screen");
  delay(1000); //Wait a second
  for (int l = 0; l < 16; l++) { //For loop. Repeating 16 times
    lcd.scrollDisplayRight(); //Scroll whole screen to the right once
    delay(90); //Slight delay for animation
  }
  delay(1000);
  for (int l = 0; l < 16; l++)
    lcd.scrollDisplayLeft();
  for (int l = 51; l > -1; l--) { //Repeating 51 times
    analogWrite(bri, l * 5);
    delay(35);
  }
  delay(1000);
  digitalWrite(bri, HIGH);
  for (int l = 0; l < 51; l++) { //Repeating 51 times
    analogWrite(contra, l * 5);
    delay(35);
  }
  delay(1000);
  digitalWrite(contra,LOW);
  lcd.setCursor(0, 0);
}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Schematics

LCD Setup
Breadboard View
Lcdsetup

Comments

Similar projects you might like

Lcd Display in Real Time.

Project tutorial by Youssef Sabaa

  • 22,581 views
  • 5 comments
  • 49 respects

Portable Arduino Temp/Humidity Sensor with LCD

Project tutorial by ThothLoki

  • 153,335 views
  • 115 comments
  • 185 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 45,335 views
  • 4 comments
  • 37 respects

Bluetooth control led with lcd led status display real time.

Project tutorial by Youssef Sabaa

  • 17,304 views
  • 4 comments
  • 34 respects

Soil Moisture Sensor With LCD Display

Project tutorial by Patel Darshil

  • 21,879 views
  • 5 comments
  • 39 respects
Add projectSign up / Login