Skip to content

"Hello, world!" Project with LCD 1602 module

As time goes on, the number of components, modules and ideas for Arduino-based projects grows! This time, a widespread component that is an indispensable part of any embedded system will be covered. It is a component whose purpose is to display data - textual or numerical, LCD module 1602a. Introduction to the characteristics of the component, mode of operation and its programming will be illustrated with the help of two simple programs (sketches). The first is "Hello, world!", Which performs a simple display of textual data on the display, while the second includes a display of data obtained from the keyboard.

Video tutorial

LCD 1602a module

LCD 16x2 module
Figure 1 - LCD 1602a module

The 1602a LCD screen module (Figure 1) is widespread and often used in embedded systems due to its availability, low cost, and ease of programming. The name 1602 means that the LCD screen has 16 columns and 2 rows, so it is possible to display a total of 32 characters. Each character is displayed over a grid of 8 * 5 pixels (Figure 2). The contrast of the screen is adjusted using a potentiometer whose middle terminal is connected to pin 3 - VE. Proper operation is provided by an external library „LiquidCrystal.h“.

LCD_16x2_model
Figure 2 - Physical properties of modules and screen
LCD_16x2_pinout
Figure 3 - pinout

Pinout of LCD 1602a module

Pin #PinDescription
1VSSGND pin
2VDDLCD power supply + 5V (permissible voltage 4.7 - 5.3V)
3VEScreen contrast
4Register Select (RS)Module mode selection (0 = data mode and 1 = command mode)
5Read/WriteRead / Write (0 = write operation and 1 = read operation)
6Enable0 inactive state; 1 = processing of incoming data
7-14Data Pin 0 – 7Data pins (possible mode is 4b or 8b)
15LED Positive (A)Anode (for backlight control)
16LED Positive (C)Cathode (for backlight control)
Figure 3 and Table 1 - Pinout of LCD 1602a module

The features of this LCD are:

  • The operating voltage of the LCD is 4.7-5.3 volts.
  • Contains two lines in which each line can produce 16 characters.
  • Power consumption is 1 milliampere without backlight.
  • Each character can be made with a grid of 5 * 8 pixels.
  • Characters are alphanumeric
  • The screen can operate in 2 modes - 4-bit and 8-bit
  • Available in blue or green backlight.
  • Displays user-defined characters.

Electrical scheme

Електрична шема
Electrical scheme

Example 1 - sketch "Hello world!"

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // подешавање димензија екрана
  lcd.begin(16, 2);
  // приказ поруке
  lcd.print("hello, world!");
}

void loop() {
  // постављање курсора у колону 0, ред 1
  // (ред 1 је други ред, јер бројање редова почиње од 0):
  lcd.setCursor(0, 1);
  // приказ протеклог времена у секундама од претходног ресетовања
  lcd.print(millis() / 1000);
}

Example 2 - sketch display of keyboard entered data

// укључивање библиотеке
#include <LiquidCrystal.h>
// дефинисање променљивих на које су повезани одговарајући пинови ЛЦД екрана са
// вредностима Ардуино пинова на које је ЛЦД екран повезан
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
  // Подешавање димензија екрана
  lcd.begin(16, 2);
  // иницијализација серијске комуникације
  Serial.begin(9600);
}
void loop() {
  // када се унесе карактер путем серијског монитора
  if (Serial.available()) {
    // додато чекање да би пристигли сви унети подаци
    delay(100);
    // очисти екран
    lcd.clear();
    // читање свих унетих карактера
    while (Serial.available() > 0) {
      // приказ појединачног карактера на екран
      lcd.write(Serial.read());
    }
  }
}
en_USEnglish
Powered by TranslatePress