Keypad and Display Laboratory Instructions
Keypad and Display Laboratory Instructions
Overview
This laboratory has three parts. First, you will connect a liquid crystal display (LCD) to the Arduino and
display a message. Second, you will type a short message on your computer and display it on the LCD.
Third, you will connect a 4x4 matrix keypad to the Arduino and display its key presses on the LCD.
Background
How Liquid Crystal Displays (LCDs) Work
The screen of LCDs is made of pixels. Text is created using these pixels, and the programmer can control
each individual pixel. Characters are displayed by controlling the pattern of the pixels.
Figure 1
LCDs can be monochrome (mono-colored) or colored. In monochrome LCDs, each pixel can be on or off,
or different shades of gray. In colored LCDs, each pixel can have different colors. The colored pixels can
display red, green, and blue. The three primary colors can be combined to make different colors.
Figure 2
Beneath each key is a membrane switch, like those used for many computer keyboards. Each switch in a
row is connected to the other switches in the same row by a conductive trace underneath the pad. The
switches in a column are connected the same way; one side of the switch is connected to all the other
switches by a conductive trace. Each row and column are brought out to a single pin, for a total of eight
pins on a 4x4 keypad.
Figure 3
Pressing a button closes the switch between a column and a row trace, allowing current to flow between
a column pin and a row pin. The Arduino determines which button is pressed by detecting the row and
pin that is connected to the button.
1. When no buttons are pressed, all the column pins are held HIGH, and all of the row pins are held
LOW.
Figure 4
2. When a button is pressed, the column pin is pulled LOW because the current from the HIGH
column flows to the LOW row pin.
Figure 5
3. The Arduino now knows which column the button is in, so now it needs to find the row it is in. It
does this by switching each one of the row pins HIGH, and at the same time reading all the
column pins to detect which column pin returns to HIGH.
Figure 6
4. When the column pin goes HIGH again, the Arduino has found the row pin that is connected to
the button.
Figure 7
Computer keyboards work on the same principle. A simple processor in the keyboard performs the same
function as the Arduino does in this example. It then notifies the computer which key has been pressed.
1. Install the LiquidCrystal I2C Library written by Marco Schwartz by following these steps:
a. Download the LiquidCrystal_12C library.
b. From the Arduino IDE, select Sketch > Include Library > Add .Zip Library. Figure 9
demonstrates the path.
Figure 9
2. Connect the 1602 LCD to the Arduino Uno by following these steps:
NOTE: The male-to-female jumpers are set together in a ribbon in the kit; you will have to split
the ribbon to complete the next steps.
a. Connect GND on the LCD to GND on the Arduino with a male-to-female jumper.
a. Download HelloWorld.ino.
b. Select HelloWorld.ino in your Downloads directory. The popup window titled Moving will
open.
Figure 12
c. Select OK. The Arduino IDE will open, showing the HelloWorld sketch.
e. After the sketch compiles and downloads, the LCD will display the message “Hello, world!
ECEN 106 is fun!” (See Figure 21).
f. If you do not see a message, check your wiring. If you still do not see the message, try turning
the screw on the I2C module on the back of the LCD. The screw controls the brightness of the
display.
Figure 14
g. Edit the sketch to display your first name on the top line and your last name on the bottom
line. While editing the sketch, be sure to leave the quotation marks in the code.
i. Take a photo of the display showing your name and submit it in JPG format for your laboratory
report.
a. Download SerialDisplay.ino.
b. Select SerialDisplay.ino in your Downloads directory. The popup window titled Moving will
open.
Figure 15
c. Select OK. The Arduino IDE will open, showing the SerialDisplay sketch.
e. Select the Serial Monitor button, shown circled in red in Figure 16.
Figure 16
Figure 17
g. Type a short message in the console, then press Enter on your keyboard. The message will
appear on the LCD. See Figure 18 for an example.
Figure 18
Figure 19
h. Take a photo of the display showing your message and submit it in JPG format for your
laboratory report.
1. Install the Keypad Library written by Mark Stanley and Alexander Brevig by following these steps:
a. From the Arduino IDE, select Sketch > Include Library > Manage Libraries. Figure 20
demonstrates the path.
Figure 20
b. When the Library Manager window opens, search for keypad and scroll down to Keypad by
Mark Stanley, Alexander Brevig. See Figure 21 for an example.
Figure 21
c. Select Install. Keypad will be listed under the heading of Contributed Libraries.
2. Connect the 4x4 matrix keypad to the Arduino Uno by following these steps:
a. Connect pin 1 (far-right pin) of the keypad to pin 2 of the Arduino with a male-to-male
jumper.
b. Connect pin 2 of the keypad to pin 3 of the Arduino with a male-to-male jumper.
c. Connect pin 3 of the keypad to pin 4 of the Arduino with a male-to-male jumper.
d. Connect pin 4 of the keypad to pin 5 of the Arduino with a male-to-male jumper.
e. Connect pin 5 of the keypad to pin 6 of the Arduino with a male-to-male jumper.
f. Connect pin 6 of the keypad to pin 7 of the Arduino with a male-to-male jumper.
g. Connect pin 7 of the keypad to pin 8 of the Arduino with a male-to-male jumper.
h. Connect pin 8 (far-left pin) of the keypad to pin 9 of the Arduino with a male-to-male jumper.
Figure 22
a. Download KeyPadDisplay.ino.
b. Select KeyPadDisplay.ino in your Downloads directory. The popup window shown in Figure
23 will open.
Figure 23
c. Select OK. The Arduino IDE will open, showing the KeyPadDisplay sketch.
a. Press a key on the 4x4 matrix keypad. The pressed key will appear on the LCD.
b. Make a short video that demonstrates correct operation and submit it in MP4 format for your
laboratory report.