LCD screen: all you need to know

pantalla LCD

An LCD screen can be a solution for projects where you need to display information without having to rely on a constantly connected computer. That is, in an Arduino/Raspberry Pi project, you can use the serial port to transmit information to be displayed on the screen to get sensor readings, display some graphs, counts, etc. But if your project is constantly running or away from where you can have a computer, the LCD screen is your salvation.

For example, imagine you install an automated irrigation system and would like to check the humidity and temperature readings when you go to your garden. Having to take your computer there to connect the Arduino board to your PC is not a practical solution. In this case, you can modify your code so that the information is displayed on the LCD screen and even add some keys or buttons to display different information.

What is an LCD panel?

A Liquid Crystal Display (LCD) is a type of thin, flat panel that can display images. Each panel is made up of a certain number of colored or monochrome pixels that are placed in front of a light source. Their consumption is low, so they are ideal for this type of low power electronic DIY projects.

Each pixel on the LCD screen is composed of a layer of molecules aligned between two transparent electrodes, and two polarization filters. A liquid crystal display exists between the polarisation filters, hence its name, and prevents light passing through the first filter from being blocked by the second.

Also, if you have noticed, when you touch one of these screens the image is deformed and a kind of black spot appears when you press, that’s because you are putting pressure on the liquid crystal and it is not advisable to do it… You can end up with lower quality colors on the screen, irregular distribution of the illumination or even with dead pixels (black dots or areas on the screen that don’t go away).

LCD screens for Arduino and Raspberry Pi

An LCD display, such as the modules that exist for electronics or Arduino, usually has several columns to display alphanumeric characters or symbols and one or two rows to display information. This makes them much more interesting than a seven-segment display, which would have to be connected to several pins in order to show only one number, symbol or letter. If you want to show more you should put several displays.

With a single LCD screen, you can display much more information. But you must know the pinout of this type of module to connect them properly. I recommend you to always see the datasheet of the specific manufacturer and model that you have as they can vary.

For example, , which is one of the most popular with keyboard and contains the possibility to display up to 16 characters in each of its two lines. And there are even 20×4, or slightly more advanced multi-inch color en to show more complex images.

For the LCD screen of Adafruit 16×2 you can see this datasheet .

For Arduino perhaps a simpler one like the is better. If you look at this board, it has 16 pins on the back. If you take the board and place it upside down and look at its pins from left to right you have a pinout:

  • Pin 16: GND for backlight
  • Pin 15: Vcc for backlight
  • Pin 7-14: 8-bit (next 8 pins) to transmit the information to be displayed on the screen
  • Pin 6: read/write synchronization
  • Pin 5. R/W (write and read for data and commands)
  • Pin 4: RS (command/data selector)
  • Pin 3: Contrast control
  • Pin 2: 5v DC for power
  • Pin 1: GND (0v) for power

Remember that when you put it in its correct position the pins are reversed…

Integration with Arduino

 

Wiring diagram of LCD 16x2 to Arduino Uno

To connect it to Arduino is not too complicated, you just have to consider including a 220 ohm resistor to regulate the input voltage for the display power, and a potentiometer to modulate the display contrast. Then connect each of the pins to the Arduino board properly and that’s it. You can look at Fritzing’s image…

As you can see, the potentiometer will be through which the LCD screen will be fed and also the contrast will be regulated. So it will be connected to both GND and Vcc of the display, as well as to the backlight control line and contrast control. Maybe that’s the most complicated part, then it’s a matter of connecting the remaining pins to the inputs/outputs you are going to use in your project.

Programming with Arduino IDE

For the programming you must take into account some peculiarities, keep in mind that you must not only know how to send data, but also move it, place it well on the screen, etc. And you should also use a library called LiquidCrystal.h, provided that your LCD screen has a compatible Hitachi HD44780 chipset. An example of code is here:


#include <LiquidCrystal.h>

// We define the constants
#define COLS 16 // Here's the number of columns on the LCD, 16 in our case
#define ROWS 2 // Here the rows x2
#define SPEED 200 // Speed at which the text will move

// We indicate the interface pins where you have connected the LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// For the text shown
String row_text = "Example LCD";

void setup() {
  // Configure the serial monitor
  Serial.begin(9600);

  // Configure rows and columns
  lcd.begin(COLS, ROWS);
}

void loop() {

  // Size of text to be displayed
  int tam_text=text_row.length();

  // We indicate that the text entry is made from the left
  for(int i=tam_text; i>0 ; i--)
  {
    String text = row_text.substring(i-1);

    // Clean the screen to be able to show different information
    lcd.clear();

    // Place the cursor in the right place, in this case at the beginning
    lcd.setCursor(0, 0);

    // We write the text "Example LCD"
    lcd.print(text);

    // It will wait the specified number of milliseconds, in this case 200
    delay (SPEED);
  }

  // Move the text to the left in the first row
  for(int i=1; i<=16;i++) {
    lcd.clear();
    lcd.setCursor(i, 0);
    lcd.print(row_text);
    delay(SPEED); }
  // Move the text to the left in the second row
    for(int i=16;i>=1;i--)
  {
    lcd.clear();
    lcd.setCursor(i, 1);
    lcd.print(row_text);
    delay(SPEED);
  }
  for(int i=1; i<=tam_text ; i++)
  {
    String text = row_text.substring(i-1);
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print(text);
    delay(SPEED);
  }
}

More information – Arduino Programming Manual (free PDF)

Leave a Comment

*

*