# Interfacing LCD with Arduino

Interfacing LCD with Arduino ... Fig. 3: Voltage Divider series such that R 1 is connected to GND and R 2 is connected to V cc. Refer to Fig. 3 Proble...

1

Interfacing LCD with Arduino

G V V Sharma∗

R1 (known)

A0

VCC

R2 (unknown)

Abstract—Through this manual, we learn how to measure an unknown resistance through arduino and display it on an LCD.

Fig. 3: Voltage Divider

1 Components Component Resistor Arduino LCD Jumper Wires

Value 220 Ohm 1K Uno 16 × 2

GND

Quantity 1 1 1 1 20

TABLE I

2 Measuring the resistance Problem 1. Connect the 5V pin of the Arduino to an extreme pin of the Breadboard shown in Fig. 1. Let this pin be Vcc .

series such that R1 is connected to GND and R2 is connected to Vcc . Refer to Fig. 3 Problem 4. Connect the junction between the two resistors to the A0 pin on the Arduino. Problem 5. Connect the arduino to the computer so that it is powered. Problem 6. Open the Arduino IDE and type the following code. Open the serial monitor to view the output.

Problem 3. Let R1 be the known resistor and R2 be the unknown resistor. Connect R1 and R2 in

/ / Declarations i n t V out q =0 ; / / V out q i s t h e q u a n t i z e d v o l t a g e f l o a t V in = 5 , V out ; / / V in = V cc f l o a t R1 =220 , R2 ; / / R1 i s known r e s i s t a n c e / / R2 i s unknown r e s i s t a n c e

*The author is with the Department of Electrical Engineering, Indian Institute of Technology, Hyderabad 502285 India e-mail: [email protected] All content in the manual released under GNU GPL. Free to use for anything.

void s e t u p ( ) { / / Get t h e r e s u l t o n t o t h e s e r i a l

Problem 2. Connect the GND pin of the Arduino to the opposite extreme pin of the Breadboard.

2

TABLE II: Arduino to LCD Pin Connection. Arduino Pins

LCD Pins

GND 5V GND D12

1 2 3 4

LCD Pin Label GND Vcc Vee RS

GND D11 D5

5 6 11

R/W EN DB4

}

D4

12

DB5

void loop ( ) { / / V 0ut q i s an i n t e g e r b e t w e e n 0 t o 1023 V out q=a n a l o g R e a d ( 0 ) ; / / r e a d i n g f r o m A0

D3

13

DB6

D2

14

DB7

5V GND

15 16

LED+ LED-

Fig. 7: lcd monitor S e r i a l . begin (9600) ;

/ / V out i s t h e a c t u a l v o l t a g e a t t h e j u n c t i o n o f R1 and R2 V out = V in∗V out q / 1 0 2 4 ; R2 = R1 ∗ ( ( V in ) / ( V out ) − 1 . 0 ) ; delay (3000) ; S e r i a l . p r i n t l n ( R2 ) ; } 3 Display Resistance on LCD Problem 7. Plug the LCD in Fig. 7 to the breadboard. Problem 8. Connect the 220Ω resistance from Vcc to pin 15 (Led+) of the LCD. Problem 9. Connect the Arduino pins to LCD pins as per Table II. Problem 10. Include the instructions for the LCD in the code for measuring the resistance. Solution: # i n c l u d e < L i q u i d C r y s t a l . h> LiquidCrystal lcd (12 ,11 ,5 ,4 ,3 ,2) ; / / a r d u i n o p i n s c o n n e c t e d t o LCD

LCD Pin Description

Contrast Register Select Read/Write Enable Serial Connection Serial Connection Serial Connection Serial Connection Backlight Backlight

/ / Declarations i n t V out q =0 ; / / V out q i s t h e q u a n t i z e d v o l t a g e f l o a t V in = 5 , V out ; / / V in = V cc f l o a t R1 =220 , R2 ; / / R1 i s known r e s i s t a n c e / / R2 i s unknown r e s i s t a n c e void s e t u p ( ) { / / Get t h e r e s u l t o n t o t h e s e r i a l monitor lcd . begin (16 ,2) ; lcd . setCursor (0 ,0) ; l c d . p r i n t ( ”−−−−OHM METER−−−” ) ; S e r i a l . begin (9600) ; } void loop ( ) { / / V 0ut q i s an i n t e g e r b e t w e e n 0 t o 1023 V out q= a n a l o g R e a d ( 0 ) ; / / r e a d i n g

3

f r o m A0 / / V out i s t h e a c t u a l v o l t a g e a t t h e j u n c t i o n o f R1 and R2 V out = V in∗V out q / 1 0 2 4 ; R2 = R1 ∗ ( ( V in ) / ( V out ) − 1 . 0 ) ; delay (3000) ; S e r i a l . p r i n t l n ( R2 ) ; lcd . setCursor (0 ,1) ; l c d . p r i n t ( ”R = ” ) ; l c d . p r i n t ( R2 ) ; l c d . p r i n t ( ”Ohm” ) ; }

1)

2)

3) 4)

4 Explanation We create a variable called analogPin and assign it to 0. This is because the voltage value we are going to read is connected to analogPin A0. The 10-bit ADC can differentiate 1024 discrete voltage levels, 5 volt is applied to 2 resistors and the voltage sample is taken in between the resistors. The value which we get from analogPin can be between 0 and 1023. 0 would represent 0 volts falls across the unknown resistor. A value of 1023 would mean that practically all 5 volts falls across the unknown resistor. Vout represents the divided voltage that falls across the unknown resistor. The Ohm meter in this manual works on the principle of the voltage divider shown in Fig. 3. R1 Vout = Vin (10.1) R1 + R2 ! Vin −1 (10.2) ⇒ R2 = R1 Vout In the above, Vin = 5V, R1 = 220Ω.