Controlling a 16 × 2 LCD with Arduino
In this post
you will find some basic tests of the 16 × 2 LCD display with
Arduino, a very common display with HD44780 controller, which adapts to the
most diverse projects, and can be used with several models of boards and
microcontrollers such as Arduino, Raspberry Pi, PIC, etc.
This LCD the display has 16 columns and 2 rows, with a blue backlight and
white letters. For connection, there are 16 pins, of which we use 12 for a
basic connection, including the power connections (pins 1 and 2), backlight
(pins 15 and 16) and contrast (pin 3).
16 × 2 LCD display connection with Arduino
When connecting
the display to the Arduino Uno, we will use only 4 data pins (digital pins 2,
3, 4 and 5), and 2 control pins (digital pins 11 and 12).
For adjusting
the contrast, we use a 100K potentiometer, but you can test with other values
like 10K or 50K, for example.
Controlling a 16 × 2 LCD with Arduino |
If you prefer,
you can also use a potentiometer to adjust the backlight, on pins 15 and 16 of
the display. Another option is to use a resistor on one of these pins.
LCD control program
The control of
this display can be done using the LiquidCrystal library ,
already built into the Arduino IDE.
At the
beginning of the program (line 8), we define the pins that will be used by the
displays, in this format:
LiquidCrystal
lcd ( <RS pin> , <enable pin> , <pin
D4> , <pin D5> , <pin D6> , <pin
D7> )
In setup, we
initialize the display by defining the number of columns and rows with the
command lcd .begin ( 16.2 ) .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
//Programa: Teste de Display LCD 16 x 2 //Autor: FILIPEFLOP //Carrega a biblioteca LiquidCrystal #include <LiquidCrystal.h> //Define os pinos que serão utilizados para ligação ao
display LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { //Define o número de colunas e linhas do LCD lcd.begin(16, 2); } void loop() { //Limpa a tela lcd.clear(); //Posiciona o cursor na coluna 3, linha 0; lcd.setCursor(3, 0); //Envia o texto entre aspas para o LCD lcd.print("FILIPEFLOP"); lcd.setCursor(3, 1); lcd.print(" LCD 16x2"); delay(5000); //Rolagem para a esquerda for
(int posicao
= 0; posicao < 3; posicao++) { lcd.scrollDisplayLeft(); delay(300); } //Rolagem para a direita for
(int posicao
= 0; posicao < 6; posicao++) { lcd.scrollDisplayRight(); delay(300); } } |
The program
above places the text in the desired position using the command lcd.setCursor
() , and prints the string on the screen using lcd.print
("Text") . After 5 seconds, the commands scrollDisplayLeft
() and scrollDisplayRight () are used to “move” the
characters to the left and to the right, respectively.
Controlling a 16 × 2 LCD with Arduino |
Conclusion
I hope you understand better about this Controlling a 16 × 2 LCD with Arduino because I cover this topic of Controlling a 16 × 2 LCD with Arduino with details. So now you can control any Arduino LCD project without any hesitation.
Did you like
it? Leave your comment bellow
No comments
Note: Only a member of this blog may post a comment.