Monday, October 3, 2016

Learn Arduino Programming | Connecting LCD with Arduino

Arduino UNO Tutorial 10 - LCD 

We are now going to add an LCD display to our Arduino. The Arduino IDE comes with an example LCD sketch which uses an Hitachi HD44780 compatible LCD. We will use a similar LCD (Pololu 16x2 Character LCD 773 or 772)

We are going to use JHD162 LCD which is 16X 2 LCD. 
Link for the datasheet is

http://www.datasheetspdf.com/PDF/JHD162A/512991/1

The contrast pin on the LCD requires a fairly small voltage for ideal display conditions,here we have connected a fixed resistance. The lower the voltage the higher the contrast and vice versa. A voltage of approx 0.5V to 1V is about right, but depends on the ambient temperature. 


Here are the pinouts from the LCD and the corresponding pin connection on the Arduino
LCD PinSymbolFunctionArduino Pin
1Vssground (0 V)ground (0 V)
2Vddpower (4.5 – 5.5 V)+5V
3Vocontrast adjustment9
4RSH/L register select signal12
5R/WH/L read/write signalground (0 V)
6EH/L enable signal11
11DB4H/L data bus for 4-bit mode5
12DB5H/L data bus for 4--bit mode4
13DB6H/L data bus for 4-bit mode3
14DB7H/L data bus for 4-bit mode2




And here is the Arduino Sketch. The PWM output to control the contrast is done in the setup routine, however, if you wanted to be able to control the contrast manually, then the addition of two push buttons and a bit more coding would allow you to increase and decrease the contrast in simple steps within the program.


// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // declare pin 9 to be an output:
  pinMode(9, OUTPUT);  
  analogWrite(9, 50);   
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("  HobbyTronics");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

Hope you like it!

Step by Step Youtube Video coming up soon.




No comments: