Find fresh tutorials related to Arduino, Raspberry Pi, 555 Timer and many more microcontrollers. Learn something new everyday!



Tuesday, 30 December 2014

Interfacing a 16X2 LCD with Arduino - Displaying "Hello, World!" [ARDUINO]



You might have seen me using the 16X2 JHD16A LCD many times in my tutorials. Many of you might be new to this component. So what is the 16X2 LCD all about? Let's see.

What this tutorial does?
Teaches you the basics of an JCD16A 16X2 LCD, including the pin mapping, hardware and controlling it. and lets you display "Hello, World!" on the LCD with an Arduino. In the many upcoming articles and tutorials, we'll keep learning new ways of displaying messages and learn how to scroll the letters. We'll also create small animations too. But, in this one, we'll simply display "Hello, World!" in the first row and "Arduino is Fun." in the second.


Let's Learn The Basics! 
The JHD16A is a pretty popular module among the tinkerers mainly because it's cheap, and a perfect output device for many projects. It's also small. There might be many other alternatives and manufacturers. But the one I bought is made by JHD. When you buy the module, you might not get the headers soldered. There are 16 ports on it, which can be soldered to headers or directly to wires(if your project is permanent). But still I would suggest you to solder headers on it, because even if your project is permanent, you might occasionally need to check the health of your components in the project and that  in turn, would require maintenance. But again, that's entirely upto you.

If you are poor at soldering, I recommend you to read these articles:


The JHD16A is based on the Hitachi HD44780 . (Read more here: Hitachi HD44780 LCD controller) And the good thing is that, the Arduino 1.0.6 IDE, has inbuilt support for this controller. So, there's no need of downloading any library! We can get started easily.

Now, some geeky stats about the JHD16A module:

The pin config:

Copyrights: Instructables


 Pin No.
 Function of the pin
 Name
1
Ground (0V)
    VSS
2
Supply voltage; 5V (4.7V – 5.3V)
    VCC
3
Contrast adjustment; through a variable resistor
    VEE
4
Selects command register when low; and data register when high
    RS
5
Low to write to the register; High to read from the register
    R/W
6
Sends data to data pins when a high to low pulse is given
    E
7
8-bit data pins
    DB0
8
    DB1
9
    DB2
10
    DB3
11
    DB4
12
    DB5
13
    DB6
14
    DB7
15
Backlight VCC (5V)
    LED+
16
Backlight Ground (0V)
    LED-

PLEASE, NOTE THAT THE TOP LEFT PIN IS PIN NO.1. THIS IS BECAUSE, IN MY LCD, THE "JHD 16A" WAS PRINTED UPSIDE DOWN, WHICH MADE ME PRETTY CONFUSED! REFER THIS PICTURE:




Also, we shall never use the 4 pins DB0, DB1, DB2 AND DB3, because, we'll be using only the 4-bit mode everytime we print something on the LCD. So, it's completely safe to ignore it!


Materials Required:
1. PC with Arduino IDE installed!
2. Arduino UNO or NANO or PRO MINI
3. Jumpers
4. One 16X2 LCD
5. Three 1K and one 10K resistor.
6. Breadboard


Procedure:
Software part:
1. FIRST UPLOAD THE SKETCH WITHOUT CONNECTING ANY COMPONENTS ACROSS THE ARDUINO PINS

2. Don't power on the Arduino, yet.

Hardware part:
1. Make the connections as shown: Please remember this config because we'll never ever change this configuration in any of the tutorials.



THE SETUP


Now, power on the arduino.


Sketch:

/* 
 * ON PUBLIC DOMAIN
 * Author         : Nitish Dash
 * Name           : HELLO WORLD Display on 16X2 LCD
 * Created        : 12/30/2014
 * Webpage        : http://goo.gl/NjOEsH
 * Author Email   : nitishdash95@gmail.com
 * Author Website : http://www.nitishdash.com/
 **** DONOT COPY AND PLAGIARATE WITHOUT THE AUTHOR'S PERMISSIONS ****
 */
#include 

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2); //column and rows 
  lcd.print("Hello, World!");
  lcd.setCursor(0, 1);
  lcd.print("Arduino Is Fun.");
}

void loop() {
}

Please take care to remove the line 24 from the code before uploading
How this works (Algorithm):
It's simple. The command:
lcd.begin(16, 2);

initialises the LCD.

By using the command:
lcd.print("TEXT HERE");

we can easily print any text to the LCD (upto 16 characters).
To shift the cursor to 2nd row, use the command:
lcd.setCursor(0, 1);
and then again you can use:
lcd.print("TEXT HERE, AGAIN");

to print.

Video:
Coming soon.....


Downloads:
1. 16X2 LCD JHD16A DATASHEET
2. sketch.ino

Something for you!
Try these ideas to enhance your knowledge and test yourself:




0 comments:

Post a Comment

Leave your valuable feedback and suggestions.

Upcoming projects!

1. Programming ESP8266 using NodeMCU and LUA Scripts

2. IoT Applications

3. NRF42L01 2.4 GhZ module interfacing with arduino

4. ESP8266 - Everything cool about it!

Language ain't any barrier!

Get Updates!

Enter your email address:


Get the latest projects delivered into your inbox, hot!