Description
LCD stands for Liquid Crystal Display. This is a basic 16 character by 2 line display Yellow Back light . Utilizes the extremely common HD44780 parallel interface chipset. You will need 7 general I/O pins(If use in 4-bit Mode) to interface to this LCD screen. Includes LED backlight.
Features:
- LCD display module with Yellow Backlight
- SIZE : 16×2 (2 Rows and 16 Characters Per Row)
- Can display 2-lines X 16-characters
- Operate with 5V DC
- Wide viewing angle and high contrast
- Built-in industry standard HD44780 equivalent LCD controller
- Commonly Used in: Student Project, Collage,copiers, fax machines, laser printers, industrial test equipment, networking equipment such as routers and storage devices
- LCM type: Characters
How to get started with LCD 16×2
Introduction
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16×2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. 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.
overview
In this tutorial you will learn how to use LCD 16×2 display (and 20×4) with Arduino uno. Also you will learn how to display live data from a sensor. In our case we are going to use a DHT22 temperature and humidity sensor.
Parts needed:
Before we starting Uploading Arduino sketches, We must do the following hardware connection.
The connections are easy, see the image above with the breadboard circuit schematic.
Arduino library and sample code
After making the circuit as shown above we are going to download Adafruits’s DHT library from their github page. To download, click the DOWNLOADS button in the top right corner. Rename the uncompressed folder DHT and make sure that it contains the dht.cpp file and others. Then drag the DHT folder into the arduinosketchfolder/libraries/ folder. You may have to create that libraries sub-folder if it doesn’t exist. Restart the IDE. MPORTANT: As of version 1.3.0 of the DHT library you will also need to install the Adafruit_Sensor library, which is available from the Arduino library manager. Another library we will use comes with any Arduino IDE nomatter what the version you have. After installing the libraries, it’s time for testing our LCD and DHT22 temperature sensor.
Testing our DHT22 temperature sensor
if you made the circuit well as in the schematic upload this sketch to your Arduino UNO board and open your serial monitor at a baud rate speed equal to 9600.
#include <DHT.h> #define DHTPIN 6 // what pin we're connected to // Uncomment whatever type you're using! //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor DHT dht(DHTPIN, DHTTYPE); float tF; float dP; float dPF; void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin(); } void loop() { // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); float t = dht.readTemperature(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); // Serial.print(t); // Serial.print(" *C "); tF=((t*9)/5)+32; Serial.print(tF); Serial.print(" *F "); Serial.print(" \t"); Serial.print("Dew Point: "); // Serial.print(dewPointFast(t, h)); // Serial.print(" *C "); dP=(dewPointFast(t, h)); dPF=((dP*9)/5)+32; Serial.print(dPF); Serial.print(" *F"); Serial.print(" \t"); Serial.print("Heat Index: "); Serial.print(heatIndex(tF,h)); Serial.println(" *F"); } } // delta max = 0.6544 wrt dewPoint() // 6.9 x faster than dewPoint() // reference: http://en.wikipedia.org/wiki/Dew_point double dewPointFast(double celsius, double humidity) { double a = 17.271; double b = 237.7; double temp = (a * celsius) / (b + celsius) + log(humidity*0.01); double Td = (b * temp) / (a - temp); return Td; } double heatIndex(double tempF, double humidity) { double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5= -6.838e-3, c6=-5.482e-2, c7=1.228e-3, c8=8.528e-4, c9=-1.99e-6 ; double T = tempF; double R = humidity; double A = (( c5 * T) + c2) * T + c1; double B = ((c7 * T) + c4) * T + c3; double C = ((c9 * T) + c8) * T + c6; double rv = (C * R + B) * R + A; return rv; }
Yourserial monitor should print the temperature and humidity of the room you are into ( if you’re into a room like I am, you can go outside also to see if the DHT22 will show you different value). The value are presented both in degree Celsius and degree Fahrenheit. The value heat point is the temperature we feel while the temperature is the actual thermometer reading.
Testing our LCD 16×2
Before you download and upload the following sketch you must be familiar with basic functions used in this sketch. I explained three of them but there are other many functions you can use, just google them and you will find a bunch of them.
The lcd.begin(16,2) command set up the LCD number of columns and rows, if you have an LCD with 20 columns and 4 rows (20×4) you will have to change this to lcd.begin(20×4).
The lcd.print(“–message–“) command print a message to first column and row of lcd display. The “message” must have maximum length equal to lcd columns number. For example, for 16 columns display max length is equal with 16 and for 20 columns display max length is equal with 20.
The lcd.setCursor(0,1) command will set cursor to first column of second row. If you have an LCD 20×4 and you want to print a message to column five and third row you have to use: lcd.setCursor(4,2).
You can keep playing with that by clicking the “Edit” button and start making your own modifications to the code. For example, try to change message on first and second row. You have successfully completed one more Arduino “How to” tutorial and you learned how to use an LCD display with Arduino uno.
Package includes: 1×LCD 16x2 1602 1×Male Single Row Pin header (16pins)