![Using 1602 LCD Keypad Shield w/ Arduino [w/ Examples]](https://hackster.imgix.net/uploads/attachments/869010/arduino-keypad-shield-teaset-900x600_lsCSTbjFGi.jpg?auto=compress%2Cformat&w=900&h=675&fit=min)
Lo que usaremos en este proyecto
Componentes de Hardware
-
Arduino Uno R3 ×1 (Comprar Aquí)
-
Shield LCD 16×2 con Botonera para Arduino ×1. (Comprar aquí)
Software y Servicios en Línea
Descripción General
En este tutorial, aprenderás cómo utilizar el Arduino LCD Keypad Shield a través de 3 proyectos prácticos.
Lo que aprenderás:
-
Cómo configurar el shield e identificar las teclas.
-
Cómo realizar el desplazamiento de texto (scroll).
-
Cómo mostrar caracteres especiales en la pantalla.
Características de un Shield LCD 16×2 con Arduino
Mostrar información en proyectos electrónicos siempre ha sido un aspecto fundamental. Existen diversas formas de visualizar datos: desde opciones simples como leds o displays de 7 segmentos, hasta soluciones más completas como las pantallas LCD. El uso de LCDs es una de las opciones más populares y se dividen en dos tipos genéricos: Alfanuméricas (de caracteres) y Gráficas.
Una de las opciones más comunes, económicas y sencillas es la pantalla LCD de caracteres. Esta consta de varias filas y columnas donde se escriben letras y números en los espacios resultantes. Por ejemplo, el modelo 16×2 cuenta con 2 filas y 16 columnas, permitiendo mostrar hasta 32 caracteres en total.
Trabajar con estas pantallas es muy simple, ya que ofrecen compatibilidad total con la mayoría de microcontroladores y placas de procesamiento. Para facilitar aún más su uso, el modelo 16×2 (que incluye botones para crear menús) se fabrica en formato Shield (placa de expansión), siendo totalmente compatible con las placas Arduino.
Cómo usar el Arduino LCD Keypad Shield
El Arduino LCD Keypad Shield es una placa de expansión sencilla y fácil de usar (user-friendly).


¿Cómo leer las teclas?
En esta Shield, las 4 teclas (o 5, dependiendo del modelo) están conectadas al pin analógico A0 con el fin de ahorrar pines digitales. Por lo tanto, debemos utilizar el ADC (Conversor Analógico-Digital) para leerlas. Cuando presionas una tecla, esta devuelve un valor al pin A0 basado en un circuito divisor resistivo interno, el cual permite identificar qué tecla ha sido pulsada.

/*
Arduino 2x16 LCD - Detect Buttons
modified on 18 Feb 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include <LiquidCrystal.h>
//LCD pin to Arduino
const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;
const int pin_BL = 10;
LiquidCrystal lcd( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Electropeak.com");
lcd.setCursor(0,1);
lcd.print("Press Key:");
}
void loop() {
int x;
x = analogRead (0);
lcd.setCursor(10,1);
if (x < 60) {
lcd.print ("Right ");
}
else if (x < 200) {
lcd.print ("Up ");
}
else if (x < 400){
lcd.print ("Down ");
}
else if (x < 600){
lcd.print ("Left ");
}
else if (x < 800){
LCD.print ("Select");
}
}Veamos el código un poco más en detalle:
#include <LiquidCrystal.h>LiquidCrystal LCD( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);lcd.begin(16, 2);Configuración inicial del LCD especificando el número de columnas y filas. El primer argumento corresponde al número de columnas y el segundo al de filas.
A continuación, se presentan algunas de las funciones más importantes para trabajar con la pantalla LCD:

Puedes consultar el sitio web de Arduino para conocer más funciones.
¿Cómo desplazar un texto?
Podemos hacerlo fácilmente utilizando las funciones mencionadas anteriormente.
/*
Arduino 2x16 LCD - LCD Scroll
modified on 18 Feb 2019
by Saeed Hosseini
https://electropeak.com/learn/
*/
#include
const int RS = 8;
const int EN = 9;
const int d4 = 4;
const int d5 = 5;
const int d6 = 6;
const int d7 = 7;
const int pin_BL = 10; // arduino pin wired to LCD backlight circuit
LiquidCrystal lcd( RS, EN, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.print("Electropeak");
delay(1000);
}
void loop() {
// scroll 11 positions ("Electropeak" length) to the left
for (int positionCounter = 0; positionCounter < 11; positionCounter++) {
lcd.scrollDisplayLeft();
delay(400); //Scrolling speed
}
// scroll 27 positions ("Electropeak" length + display length) to the right
for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
lcd.scrollDisplayRight();
delay(400);
}
// scroll 16 positions (display length) to the left
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
lcd.scrollDisplayLeft();
delay(50);
}
delay(1000);
}¿Cómo mostrar un carácter específico?
Es posible crear un carácter personalizado en cada bloque de la pantalla LCD. Para lograrlo, se debe convertir el diseño deseado en un arreglo de códigos y luego mostrarlo en la pantalla.
Para generar estos códigos, se pueden utilizar herramientas en línea. Solo debes diseñar el carácter y luego copiar el arreglo generado en tu código.


/*
Arduino 2x16 LCD - LCD Special Char
modified on 18 Feb 2019
by Saeed Hosseini
https://electropeak.com/learn/
*/#includeconst int RS = 8;
const int EN = 9;
const int d4 = 4;
const int d5 = 5;
const int d6 = 6;
const int d7 = 7;
const int pin_BL = 10; // arduino pin wired to LCD backlight circuitLiquidCrystal lcd( RS, EN, d4, d5, d6, d7);
// smily face
byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
// Battery sign
byte battery[] = {
B01110,
B01010,
B11011,
B10001,
B11111,
B11111,
B11111,
B11111
};
// arrow right
byte R_arrow[8] = {
B00000,
B00100,
B00010,
B11111,
B00010,
B00100,
B00000,
B00000
};
// arrow left
byte L_arrow[8] = {
B00000,
B00100,
B01000,
B11111,
B01000,
B00100,
B00000,
B00000
};
// Ohm sign
byte ohm[8] = {
B00000,
B01110,
B10001,
B10001,
B10001,
B01010,
B11011,
B00000
};
// Heart
byte heart[8] = {
B00000,
B01010,
B10101,
B10001,
B10001,
B01010,
B00100,
B00000
};
int i = 0;
void setup(){
lcd.begin(16, 2);
lcd.createChar(0, smiley);
lcd.createChar(1, battery);
lcd.createChar(2, R_arrow);
lcd.createChar(3, L_arrow);
lcd.createChar(4, ohm);
lcd.createChar(5, heart);
lcd.createChar(6, ohm);
for (int n = 0; n < 6; n++)
{
lcd.setCursor(n * 2, 0);
lcd.write(n);
}
}
void loop(){
}lcd.createChar almacena tu arreglo en una ubicación de memoria y puedes mostrarlo utilizando lcd.write.
¿Qué sigue?
Intenta crear un menú con la capacidad de seleccionar opciones.
Código 1
/*
Arduino 2x16 LCD - Detect Buttons
modified on 18 Feb 2019 by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/ */
#include <LiquidCrystal.h>
//LCD pin to Arduino
const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;
const int pin_BL = 10;
LiquidCrystal lcd( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Electropeak.com");
lcd.setCursor(0,1);
lcd.print("Press Key:"); }
void loop() {
int x;
x = analogRead (0);
lcd.setCursor(10,1);
if (x < 60) {
lcd.print ("Right ");
}
else if (x < 200) {
lcd.print ("Up ");
}
else if (x < 400){
lcd.print ("Down ");
}
else if (x < 600){
lcd.print ("Left ");
}
else if (x < 800){
LCD.print ("Select");
}
}Código 2
/*
Arduino 2x16 LCD - LCD Scroll
modified on 18 Feb 2019
by Saeed Hosseini
https://electropeak.com/learn/
*/
#include
const int RS = 8;
const int EN = 9;
const int d4 = 4;
const int d5 = 5;
const int d6 = 6;
const int d7 = 7;
const int pin_BL = 10; // arduino pin wired to LCD backlight circuit
LiquidCrystal lcd( RS, EN, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.print("Electropeak");
delay(1000);
}
void loop() {
// scroll 11 positions ("Electropeak" length) to the left
for (int positionCounter = 0; positionCounter < 11; positionCounter++) {
lcd.scrollDisplayLeft();
delay(400); //Scrolling speed
}
// scroll 27 positions ("Electropeak" length + display length) to the right
for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
lcd.scrollDisplayRight();
delay(400);
}
// scroll 16 positions (display length) to the left
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
lcd.scrollDisplayLeft();
delay(50);
}
delay(1000);
}Código 3
/*
Arduino 2x16 LCD - LCD Special Char
modified on 18 Feb 2019
by Saeed Hosseini
https://electropeak.com/learn/
*/
#include
const int RS = 8;
const int EN = 9;
const int d4 = 4;
const int d5 = 5;
const int d6 = 6;
const int d7 = 7;
const int pin_BL = 10; // arduino pin wired to LCD backlight circuit
LiquidCrystal lcd( RS, EN, d4, d5, d6, d7);
// smily face
byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
// Battery sign
byte battery[] = {
B01110,
B01010,
B11011,
B10001,
B11111,
B11111,
B11111,
B11111
};
// arrow right
byte R_arrow[8] = {
B00000,
B00100,
B00010,
B11111,
B00010,
B00100,
B00000,
B00000
};
// arrow left
byte L_arrow[8] = {
B00000,
B00100,
B01000,
B11111,
B01000,
B00100,
B00000,
B00000
};
// Ohm sign
byte ohm[8] = {
B00000,
B01110,
B10001,
B10001,
B10001,
B01010,
B11011,
B00000
};
// Heart
byte heart[8] = {
B00000,
B01010,
B10101,
B10001,
B10001,
B01010,
B00100,
B00000
};
int i = 0;
void setup() {
lcd.begin(16, 2);
lcd.createChar(0, smiley);
lcd.createChar(1, battery);
lcd.createChar(2, R_arrow);
lcd.createChar(3, L_arrow);
lcd.createChar(4, ohm);
lcd.createChar(5, heart);
lcd.createChar(6, ohm);
for (int n = 0; n < 6; n++)
{
lcd.setCursor(n * 2, 0);
lcd.write(n);
}
}
void loop() {
}Aprende esto en un curso
Si prefieres verlo en vivo y con alguien que resuelva tus dudas, estos cursos presenciales de MCI Educación cubren el tema de este tutorial:
- Arduino en profundidad: Sensores y actuadores para proyectos reales — nivel intermedio, 12 horas presenciales en Santiago
- Arduino desde Cero: Primeros Pasos en Programación — nivel inicial, 15 horas presenciales en Santiago