Arduino Project : Easy Way to use LCD 1602 on Arduino

Liquid-Crystal Display (LCD) is one component that is often used in various Arduino projects. With LCD, we can easily read the result information from our project. This makes human-machine interaction even more enjoyable️

In this project, we will learn how to use the LCD 1602 in an Arduino project. LCD 1602 is an LCD that has specifications of 16 columns and 2 rows of characters. As for what we will do in this project is to display running text (running text) on the LCD.

Before we start, it’s a good idea to first understand a few things related to LCDs such as the following. An LCD has a parallel interface, which means that the microcontroller must manipulate several interface pins simultaneously in order to control the display of the LCD. The LCD interface consists of the following pins:

Pin Register Select (RS) : this pin controls where we will store data on the LCD memory, whether in the data register which stores anything that appears on the screen, or in the instruction register which stores the next instruction to be executed.
Read/Write (R/W) pin : this pin is used to select reading mode or writing mode
Enable pin : this pin is used to enable writing to registers.
8 Data pins (D0 -D7) : these pins are data written to or read from a register.
In addition, other pins are used for the purposes of setting the display contrast (Vo), power supply (+5V and Gnd) and LED Backlight (Bklt+ and BKlt-).

The process of displaying the display on the LCD includes the following processes, including the first is the data storage process that describes something to be displayed on the screen into the data register , then the next process is the instruction storage process in the instruction register . At first glance it looks complicated, but you don’t need to worry because the LiquidCrystal Library will help us simplify all the complexities of the above process, so that we can easily use LCD in our projects and don’t have to know the low-level instructions.

Components :

Arduino Uno Board
1602 . LCD
10K Ohm Potensi Potentiometer
Resistor 220 Ohm
Pin Header (to be soldered to the LCD pin)
Jumper Cable

Sketch :
/*
LiquidCrystal Library – scrollDisplayLeft() and scrollDisplayRight()
Demonstrates the use of a 16×2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints “Hello World!” to the LCD and uses the
scrollDisplayLeft() and scrollDisplayRight() methods to scroll
the text.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried ( http://www.ladyada.net )
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int numRows = 2;
const int numCols = 16;
void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print(“Big & Family”);
lcd.setCursor(0, 2);
lcd.print(“say”);
delay(2000);
lcd.clear();
text1();
text2();
text3();
}
void text1() {
// Print a message to the LCD.
lcd.setCursor(16, 0);
lcd.print(“Happy Eid”);
lcd.setCursor(16, 2);
lcd.print(“1439H”);
delay(1000);
for (int positionCounter = 0; positionCounter < 34; positionCounter++) {
lcd.scrollDisplayLeft();
delay(400);
}
lcd.clear();
}
void text2() {
// Print a message to the LCD.
lcd.setCursor(16, 0);
lcd.print(“Taqabbalallahu”);
lcd.setCursor(16, 2);
lcd.print(“Minna wa Minkum”);
//delay(1000);
for (int positionCounter = 0; positionCounter < 40; positionCounter++) {
lcd.scrollDisplayRight();
delay(400);
}
lcd.clear();
}
void text3() {
String reportString1 = “Sorry to be born and in the heart”;
String reportString2 = ” and Inner “;
// loop over the row 0:
for (int thisCol = 0; thisCol < numCols; thisCol++) {
// set the cursor position:
lcd.setCursor(thisCol, 0);
char character = reportString1.charAt(thisCol);
lcd.write(character);
delay(200);
}
// loop over the row 1:
for (int thisCol = 0; thisCol < numCols; thisCol++) {
// set the cursor position:
lcd.setCursor(thisCol, 1);
char character = reportString2.charAt(thisCol);
lcd.write(character);
delay(200);
}
delay(2000);
lcd.clear();
}

In the sketch above we will display text in three functions. The first function, text1(), returns the running text that runs from right to left. The second function text2(), returns the running text that runs from left to right. Meanwhile, the third function, text3(), displays running text that runs from left to right with one character at a time.

The first function text1() uses the lcd.scrollDisplayLeft() command to move text from right to left. Then the second function text2() uses the lcd.scrollDisplayRight() command to move the text from left to right.

While the third function text3() uses the command lcd.setCursor(), substring(), charAt() and several other commands to display text running like a typewriter typed result.

Thus the project this time, hopefully useful and thank you for visiting.

 

Leave a Reply

Your email address will not be published.