How to Program an LCD Screen

LCD screens can be useful for your Arduino projects and in this tutorial, we’re going to learn how to use one.

Requirements

  • Arduino
  • LCD Screen
  • 10 jumper wires

Schematic

Pins in order: 1.VSS-ground, 2.VDD (VCC)- supply voltage (5v), 3.V0- Contrast value of screen, 4.RS-command register at low and data register when high,5.RW- Read/Write data,6.E-Enable(Sends data to data pins)7-14.- 8 data pins,15.A-backlight (voltage (5v))16.K-backlight (ground)

Code

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//(command register pin, enable pin, digital pin 1,digital pin 2,digital pin 3,digital pin 4)

This is your object instantiation of the LCD class. The Command Register pin is used for modes and determining what should be stored in the LCD’s memory whether it’s data to be displayed on the screen (data register) or instructions (instruction register). The Enable pin allows data to be sent to the data pins when the pulse gets from high to low, mainly for instruction register purposes. The Data pins (digital pins) are the four pins that must be assigned to the LCD screen in order to work.

//no potentiometer method
void setup() {
  analogWrite(6,120);
  lcd.begin(16, 2);
  lcd.print("Hello");
  lcd.setCursor(0, 1);
  lcd.print("Human");
}

No matter what, you always need a command to control the contrast. Without it, no text will display on the screen. There are two ways of handling this. You can either attach a potentiometer to control the contrast or call analogWrite(PWM digital pin, contrast value). When using the second method, it has to be with a PWM pin, otherwise, the contrast value won’t have any effect on the screen.

//potentiometer method
void setup() {
  lcd.begin(16, 2);
  lcd.print("Hello");
  lcd.setCursor(0, 1);
  lcd.print("Human");
}

lcd.begin(number of columns, number of rows) is what instantiates the use of the LCD screen. lcd.print(“”) simply puts whatever text you put within the quotes on the LCD screen. lcd.setCursor(column,row) sets the cursor to where you want to display your text so if you want to display text on the next row on a two-row LCD screen, you input lcd.setCursor(0,1) (values begin at 0)

Final Code

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 
//(command register pin, enable pin, digital pin 1,digital pin 2,digital pin 3,digital pin 4)
void setup() {
  // set up the LCD's number of columns and rows:
  analogWrite(6,120);
  lcd.begin(16, 2);
  lcd.print("Hello");
  lcd.setCursor(0, 1);
  lcd.print("Human");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
 

}

Leave a comment

Your email address will not be published. Required fields are marked *