1602 16x2 lcd module pin factory
Do you want your Arduino projects to display status messages or sensor readings? Then these LCD displays can be a perfect fit. They are extremely common and fast way to add a readable interface to your project.
This tutorial will help you get up and running with not only 16×2 Character LCD, but any Character LCD (16×4, 16×1, 20×4 etc.) that is based on Hitachi’s LCD Controller Chip – HD44780.
True to their name, these LCDs are ideal for displaying only text/characters. A 16×2 character LCD, for example, has an LED backlight and can display 32 ASCII characters in two rows of 16 characters each.
The good news is that all of these displays are ‘swappable’, which means if you build your project with one you can just unplug it and use another size/color LCD of your choice. Your code will have to change a bit but at least the wiring remains the same!
Vo (LCD Contrast) controls the contrast and brightness of the LCD. Using a simple voltage divider with a potentiometer, we can make fine adjustments to the contrast.
RS (Register Select) pin is set to LOW when sending commands to the LCD (such as setting the cursor to a specific location, clearing the display, etc.) and HIGH when sending data to the LCD. Basically this pin is used to separate the command from the data.
R/W (Read/Write) pin allows you to read data from the LCD or write data to the LCD. Since we are only using this LCD as an output device, we are going to set this pin LOW. This forces it into WRITE mode.
E (Enable) pin is used to enable the display. When this pin is set to LOW, the LCD does not care what is happening on the R/W, RS, and data bus lines. When this pin is set to HIGH, the LCD processes the incoming data.
D0-D7 (Data Bus) pins carry the 8 bit data we send to the display. For example, if we want to see an uppercase ‘A’ character on the display, we set these pins to 0100 0001 (as per the ASCII table).
Now we will power the LCD. The LCD has two separate power connections; One for the LCD (pin 1 and pin 2) and the other for the LCD backlight (pin 15 and pin 16). Connect pins 1 and 16 of the LCD to GND and 2 and 15 to 5V.
Most LCDs have a built-in series resistor for the LED backlight. You’ll find this near pin 15 on the back of the LCD. If your LCD does not include such a resistor or you are not sure if your LCD has one, you will need to add one between 5V and pin 15. It is safe to use a 220 ohm resistor, although a value this high may make the backlight a bit dim. For better results you can check the datasheet for maximum backlight current and select a suitable resistor value.
Next we will make the connection for pin 3 on the LCD which controls the contrast and brightness of the display. To adjust the contrast we will connect a 10K potentiometer between 5V and GND and connect the potentiometer’s center pin (wiper) to pin 3 on the LCD.
That’s it. Now turn on the Arduino. You will see the backlight lit up. Now as you turn the knob on the potentiometer, you will start to see the first row of rectangles. If that happens, Congratulations! Your LCD is working fine.
Let’s finish connecting the LCD to the Arduino. We have already made the connections to power the LCD, now all we have to do is make the necessary connections for communication.
We know that there are 8 data pins that carry data to the display. However, HD44780 based LCDs are designed in such a way that we can communicate with the LCD using only 4 data pins (4-bit mode) instead of 8 (8-bit mode). This saves us 4 pins!
4-bit mode is often used to save I/O pins. However, 8-bit mode is best used when speed is required in an application and there are at least 10 I/O pins available.
The sketch begins by including the LiquidCrystal library. The Arduino community has a library called LiquidCrystal which makes programming of LCD modules less difficult. You can find more information about the library on Arduino’s official website.
First we create a LiquidCrystal object. This object uses 6 parameters and specifies which Arduino pins are connected to the LCD’s RS, EN, and four data pins.
In the ‘setup’ we call two functions. The first function is begin(). It is used to specify the dimensions (number of columns and rows) of the display. If you are using a 16×2 character LCD, pass the 16 and 2; If you’re using a 20×4 LCD, pass 20 and 4. You got the point!
After that we set the cursor position to the second row by calling the function setCursor(). The cursor position specifies the location where you want the new text to be displayed on the LCD. The upper left corner is assumed to be col=0, row=0.
There are some useful functions you can use with LiquidCrystal objects. Some of them are listed below:lcd.home() function is used to position the cursor in the upper-left of the LCD without clearing the display.
lcd.scrollDisplayRight() function scrolls the contents of the display one space to the right. If you want the text to scroll continuously, you have to use this function inside a for loop.
lcd.scrollDisplayLeft() function scrolls the contents of the display one space to the left. Similar to above function, use this inside a for loop for continuous scrolling.
If you find the characters on the display dull and boring, you can create your own custom characters (glyphs) and symbols for your LCD. They are extremely useful when you want to display a character that is not part of the standard ASCII character set.
CGROM is used to store all permanent fonts that are displayed using their ASCII codes. For example, if we send 0x41 to the LCD, the letter ‘A’ will be printed on the display.
CGRAM is another memory used to store user defined characters. This RAM is limited to 64 bytes. For a 5×8 pixel based LCD, only 8 user-defined characters can be stored in CGRAM. And for 5×10 pixel based LCD only 4 user-defined characters can be stored.
16×2 LCD is named so because; it has 16 Columns and 2 Rows. There are a lot of combinations available like, 8×1, 8×2, 10×2, 16×1, etc. But the most used one is the 16*2 LCD, hence we are using it here.
All the above mentioned LCD display will have 16 Pins and the programming approach is also the same and hence the choice is left to you. Below is the Pinout and Pin Description of 16x2 LCD Module:
These black circles consist of an interface IC and its associated components to help us use this LCD with the MCU. Because our LCD is a 16*2 Dot matrix LCD and so it will have (16*2=32) 32 characters in total and each character will be made of 5*8 Pixel Dots. A Single character with all its Pixels enabled is shown in the below picture.
So Now, we know that each character has (5*8=40) 40 Pixels and for 32 Characters we will have (32*40) 1280 Pixels. Further, the LCD should also be instructed about the Position of the Pixels.
It will be a hectic task to handle everything with the help of MCU, hence an Interface IC like HD44780 is used, which is mounted on LCD Module itself. The function of this IC is to get the Commands and Data from the MCU and process them to display meaningful information onto our LCD Screen.
The LCD can work in two different modes, namely the 4-bit mode and the 8-bit mode. In 4 bit mode we send the data nibble by nibble, first upper nibble and then lower nibble. For those of you who don’t know what a nibble is: a nibble is a group of four bits, so the lower four bits (D0-D3) of a byte form the lower nibble while the upper four bits (D4-D7) of a byte form the higher nibble. This enables us to send 8 bit data.
Now you must have guessed it, Yes 8-bit mode is faster and flawless than 4-bit mode. But the major drawback is that it needs 8 data lines connected to the microcontroller. This will make us run out of I/O pins on our MCU, so 4-bit mode is widely used. No control pins are used to set these modes. It"s just the way of programming that change.
As said, the LCD itself consists of an Interface IC. The MCU can either read or write to this interface IC. Most of the times we will be just writing to the IC, since reading will make it more complex and such scenarios are very rare. Information like position of cursor, status completion interrupts etc. can be read if required, but it is out of the scope of this tutorial.
The Interface IC present in most of the LCD is HD44780U,in order to program our LCD we should learn the complete datasheet of the IC. The datasheet is given here.
There are some preset commands instructions in LCD, which we need to send to LCD through some microcontroller. Some important command instructions are given below:
-Select-AfghanistanAlbaniaAlgeriaAmerican SamoaAndorraAngolaAnguillaAntigua and BarbudaArgentinaArmeniaArubaAustraliaAustriaAzerbaijan RepublicBahamasBahrainBangladeshBarbadosBelarusBelgiumBelizeBeninBermudaBhutanBoliviaBosnia and HerzegovinaBotswanaBrazilBritish Virgin IslandsBrunei DarussalamBulgariaBurkina FasoBurundiCambodiaCameroonCanadaCape Verde IslandsCayman IslandsCentral African RepublicChadChileChinaColombiaComorosCongo, Democratic Republic of theCongo, Republic of theCook IslandsCosta RicaCroatia, Republic ofCyprusCzech RepublicCôte d"Ivoire (Ivory Coast)DenmarkDjiboutiDominicaDominican RepublicEcuadorEgyptEl SalvadorEquatorial GuineaEritreaEstoniaEthiopiaFalkland Islands (Islas Malvinas)FijiFinlandFranceFrench GuianaFrench PolynesiaGabon RepublicGambiaGeorgiaGermanyGhanaGibraltarGreeceGreenlandGrenadaGuadeloupeGuamGuatemalaGuernseyGuineaGuinea-BissauGuyanaHaitiHondurasHong KongHungaryIcelandIndiaIndonesiaIraqIrelandIsraelItalyJamaicaJapanJerseyJordanKazakhstanKenyaKiribatiKorea, SouthKuwaitKyrgyzstanLaosLatviaLebanonLesothoLiberiaLibyaLiechtensteinLithuaniaLuxembourgMacauMacedoniaMadagascarMalawiMalaysiaMaldivesMaliMaltaMarshall IslandsMartiniqueMauritaniaMauritiusMayotteMexicoMicronesiaMoldovaMonacoMongoliaMontenegroMontserratMoroccoMozambiqueNamibiaNauruNepalNetherlandsNetherlands AntillesNew CaledoniaNew ZealandNicaraguaNigerNigeriaNiueNorwayOmanPakistanPalauPanamaPapua New GuineaParaguayPeruPhilippinesPolandPortugalPuerto RicoQatarReunionRomaniaRwandaSaint HelenaSaint Kitts-NevisSaint LuciaSaint Pierre and MiquelonSaint Vincent and the GrenadinesSan MarinoSaudi ArabiaSenegalSerbiaSeychellesSierra LeoneSingaporeSlovakiaSloveniaSolomon IslandsSomaliaSouth AfricaSpainSri LankaSurinameSwazilandSwedenSwitzerlandTaiwanTajikistanTanzaniaThailandTogoTongaTrinidad and TobagoTunisiaTurkeyTurkmenistanTurks and Caicos IslandsTuvaluUgandaUnited Arab EmiratesUnited KingdomUnited StatesUruguayUzbekistanVanuatuVatican City StateVenezuelaVietnamVirgin Islands (U.S.)Wallis and FutunaWestern SaharaWestern SamoaYemenZambiaZimbabwe
Vcc and Vss provide +5V and ground to our LCD, respectively, VEE is used for controlling LCD contrast i.e. dimming the brightness or increasing the brightness of LCD.
There are two very important registers inside the LCD. The RS pin is used for the selection of these registers. If RS=0, the instruction command code register is selected, which allows the user to send commands for the LCD such as clear display, cursor at home, and so on. If RS=1, the data register is selected. It allows the user to send data that is to be displayed on the LCD.
When data is supplied to the data pins, a high-to-low pulse must be applied to this pin in order for the LCD to latch in the data present at the data pins. This pulse must be a minimum of 450ns wide.
The 8-bit datapins, D0-D7 are used to send information to the LCD or read the contents of the LCD’s internal Registers. We send the ASCII codes is sent to the LCD to display numbers and letters for the letter A-Z, a-z, and numbers 0-9 to these pins while masking RS=1.
There are also instruction command codes that can be sent to the LCD to clear the display or force the cursor to the home position or blink the cursor.
The next table here incudes all the instruction command codes. To interface LCD to the AVR we can use 4-bit mode and 8-bit mode. The 8-bit data interfacing is easier to program but uses 4 more pins.
We come across Liquid Crystal Display (LCD) displays everywhere around us. Computers, calculators, television sets, mobile phones, and digital watches use some kind of display to display the time.
An LCD screen is an electronic display module that uses liquid crystal to produce a visible image. The 16×2 LCD display is a very basic module commonly used in DIYs and circuits. The 16×2 translates a display of 16 characters per line in 2 such lines. In this LCD, each character is displayed in a 5×7 pixel matrix.
Contrast adjustment; the best way is to use a variable resistor such as a potentiometer. The output of the potentiometer is connected to this pin. Rotate the potentiometer knob forward and backward to adjust the LCD contrast.
Sends data to data pins when a high to low pulse is given; Extra voltage push is required to execute the instruction and EN(enable) signal is used for this purpose. Usually, we set en=0, when we want to execute the instruction we make it high en=1 for some milliseconds. After this we again make it ground that is, en=0.
A 16X2 LCD has two registers, namely, command and data. The register select is used to switch from one register to other. RS=0 for the command register, whereas RS=1 for the data register.
Command Register: The command register stores the command instructions given to the LCD. A command is an instruction given to an LCD to do a predefined task. Examples like:
Data Register: The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. When we send data to LCD, it goes to the data register and is processed there. When RS=1, the data register is selected.
Generating custom characters on LCD is not very hard. It requires knowledge about the custom-generated random access memory (CG-RAM) of the LCD and the LCD chip controller. Most LCDs contain a Hitachi HD4478 controller.
CG-RAM address starts from 0x40 (Hexadecimal) or 64 in decimal. We can generate custom characters at these addresses. Once we generate our characters at these addresses, we can print them by just sending commands to the LCD. Character addresses and printing commands are below.
LCD modules are very important in many Arduino-based embedded system designs to improve the user interface of the system. Interfacing with Arduino gives the programmer more freedom to customize the code easily. Any cost-effective Arduino board, a 16X2 character LCD display, jumper wires, and a breadboard are sufficient enough to build the circuit. The interfacing of Arduino to LCD display is below.
The combination of an LCD and Arduino yields several projects, the most simple one being LCD to display the LED brightness. All we need for this circuit is an LCD, Arduino, breadboard, a resistor, potentiometer, LED, and some jumper cables. The circuit connections are below.
Winstar WH1602B is one of the most popular character LCD display module 16x2 types in the market. WH1602B 16x2 LCD display model is built in with ST7066 controller IC or equivalent; its default interface is 6800 4/8-bit parallel. The model no. WH1602B1 is having 4 line SPI interface, as to the part no. WH1602B3 is having I2C interface.
This is a tutorial to show you on how to operate LCD 16 x 2 (indicating the pannel with 2 lines of character string and each line can display 16 chars).
At first, I didn"t like much of this application mainly because it would take up too many I/O pins. I thought it would be a little bit of waste of the hardware resources just to operate this simple LCD pannel. So, at the beginning I tried to find the same LCD pannel that has I2C interface so that I can operate it with much small number of pins. But I couldn"t find such a module at the local hardware shop... finally I decided to use the module with 16 pins as it is and I thought I would learn something.
The module that I purchased is LCD-01 from OSEPP. However, I couldn"t find any detailed technical documentation on this module at OSEPP home page. However, it worked with Arduino default Sample sketch.
Following is the connection diagram between my Arduino and the LCD module (Sorry.. it is messy diagram.. but I didn"t find any nicer way with no crossovers of wires. When you build real circuit, you would need to use a breadboard since many wires are connected to single pin GND and 5V in the diagram. It would not be possible to connect like this without using a breadboard unless you have brached wires).
NOTE :This connection diagram is a little bit different from the one shown in Arduino "Hello World" example page. It is because I forgot buying a variable resistor and I found I don"t have the exact the same fixed value resistor as in the "Hello World" page. Fortunately, I got this drawing working after a little bit of struggly. The biggest difference is that I connected PIN 3 to ground (not to 5V). But you would need to put some resitor between PIN 3 and GND. I tried the direct connection without resistor.. but it didn"t work (I saw some discussion page on the web suggested the direct connection to ground, but it didn"t work for me). Another difference is the resistor value between PIN 15 and 5V. This is because I didn"t have the exactly same resitor as in Hello World example.
NOTE :Since Pin 15 and 16 is to turn on Backlight of the LCD pannel. The display would work even if you don"t connect these two pins. It would be just a little difficult to read the characters since the screen gets too dark.
You may not need to download any special library from LCD manufacturer. I think the default LCD library and sample sketch would work with most of the LCD of this type. I just run the following sample sketch.
Once you got the first example working, you may want to read a little bit of the details of the PIN description. Strangely .. in many engineering things .. we don"t usually read any document before we try .. we start reading only when we have any problem while trying.. or after making a couple things working in order to get deeper understanding. The minimum details that you need to know about this module is pin description as below.
If you would use LCD display only on your Arduino board, there wouldn"t be any reason to change the pin connection from the example shown above. But if you want to add some other modules to the board and use it in combination with the LCD, you may want to change the pin connection to the LCD pin. There would be a couple of different modification for pin mapping and the control pin as follows.
Depending on which case you would take, you need to use different parameter settings when you create lcd object in your Arduino code. If you look into LiquidCrystal.cpp in the library folder, you would find following four different constructors. You have to chose one of these contstructors properly depending on your requirement listed above. For example, if your requirement is case i), use (D). If your requirement is case ii), use (C). If the case is iii), use (A) and if the case is iv), use (B).
Even though wiring between Arduino and LCD is pretty complicated, the programing is pretty simple if you use Arduino library. However, I would suggest you to dig further details on how LCD library works at low layer. The best way to dig into these details is to look into the library source code LiquidCrystal.cpp in the library folder and analyze all the APIs definged in the source code.