In this article, we will look at connecting a simple LCD to the Arduino, and also find out what it is intended for and what are the features of writing code to work with it.
Connecting any sensors and modules to the Arduino or other platforms, we often use the port monitor for data output.
For example, if we connected a temperature sensor from the DHT family or connected some ultrasonic module to measure the distance to the nearest object, then the data from them (here it is the temperature and humidity of air or the distance in centimeters) are displayed on the computer screen.
But after all, if you made a weather station on the Arduino (even the simplest one), you will certainly want to make it autonomous and place it in some particular place in your house or apartment to keep track of the readings. In this case, keep the computer handy at all.
The usual display will come to the rescue, which will allow us to display data directly on the screen, and then you will not have to constantly go into the port monitor.
To implement the project from this article, we need the following components:
- Arduino Uno R3
- LCD 1602 16 × 2 characters I2C display with blue backlight
- 400-point breadboard
- Jumper wires kit
LCD DISPLAY OVERVIEW
The display is a rather small (by the standards of the displays) module, with an approximate size of 8 × 3 cm, mounted on a small substrate with contacts for connection.
Its main advantages can be attributed to low cost, clear display, exposure to temperature changes (from -20 to + 70 ° C), wide viewing angle, adjustable contrast and small size, as mentioned earlier.
Data on the display can be displayed in the format of 16 × 2 characters. Power supply is carried out using a voltage of 5 V. Also on the display there is a LED backlight that allows you to use it at night.
CONNECTING THE DISPLAY
The display has 16 pins for connection:
You will also need a 10 kΩ variable resistor (potentiometer) for connection.
All this is connected as in the diagram below:
|3||VO (setting contrast)|
|4||RS (teams and data)|
|5||RW (read and write)|
|7-14||(DB0…DB7) data line|
|15||A (plus lights)|
|16||K (minus backlight)|
After successfully connecting and powering up the Arduino, the display will turn on. And with the help of a resistor, you can change the brightness of the backlight.
As you can see, the connection is rather dreary, because it takes 9 pins on the Arduino board, which will significantly reduce the possibility of the board in your project (especially if it contains several modules).
For the convenience of connection, it is customary to use the I2C interface. Thanks to this bus, the number of pins used to connect the display is reduced to four.
Most often, such displays are already sold with this bus soldered on the reverse side, but you can also connect this interface to the screen yourself if you initially purchased the display without an I2C adapter.
It is also advisable not to remove the jumper, which is indicated by the yellow arrow. It is necessary for the correct operation of the module and for illumination. Also, a resistor for adjusting the contrast is already built into the i2c module itself, and it is no longer necessary to connect a variable resistor.
CONNECTING TO ARDUINO IDE
For the display, the LiquidCrystal.h library built into the Arduino IDE is used. If you connect the display using the i2c protocol, then it is better to use the LiquidCrystal_I2C.h library.
By connecting this module to Arduino, you can test its functionality by downloading the program code from the examples that are already loaded into the development environment. The location path is shown in the picture below:
The “HelloWorld” program displays the text in quotes on the display and is the easiest to work with the display.
It looks like this:
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
Also, the LiquidCrystal.h library has quite a wide functionality, which, undoubtedly, will be useful to you in further work with this module: