Logo

dev-resources.site

for different kinds of informations.

LCD 1602 Keypad Shield: How do you feel?

Published at
9/27/2024
Categories
cpp
arduino
beginners
learning
Author
yowise
Categories
4 categories in total
cpp
open
arduino
open
beginners
open
learning
open
Author
6 person written this
yowise
open
LCD 1602 Keypad Shield: How do you feel?

This simple project is meant to display the functionality of a Liquid Crystal Display 1602 Keypad Shield.
How do you feel? mimics a self- assessment tool- user can choose from 5 emotions according to the pressed button, represented by different characters:
happy (button: UP; char: smiley)
thrilled (button: RIGHT; char: heart)
sad (button: DOWN; char: sad)
surprised (button: LEFT; char: surprised)
playful (button: SELECT; char: playful).

The LCD is connected to the Arduino compatible UNO R3 board without using wires. A USB A-B cable makes the connection between the board and a source of electricity (this case, own laptop).
Here is the correspondence between the command pins:

pins

"d" stands for data . On the LCD, it's displayed with "D" (from D0 to D7).

The correspondence pins of the board are digital .
There is also a backlight control pin (not identifiable on the LCD), corresponding to digital pin 10. The backlight transistor is under the LCD module shield.

Extra info:
There are also analogue pins, from A0 to A5. The only pin used is A0: it is used by the buttons (except for RST).

  • RS stands for Register Select.

  • RS sends signals to I nstruction R egister (IR) and D ata R egister (DR).

  • IR stores the instruction codes (initialize display, clear display, cursor shift etc.), the address information for display data RAM, and the character generator RAM
    DR processes the instruction.

  • If RS= 0, instruction register selected. If RS=1, data register selected.

EN stands for Enable.

  • Starts data read/ write.
#include <LiquidCrystal.h> // is used to include outside libraries in your sketch

// LCD pin to Arduino
const int RS = 8; 
const int EN = 9; 
const int d4 = 4; 
const int d5 = 5; 
const int d6 = 6; 
const int d7 = 7; 


// create a variable of type LiquidCrystal
LiquidCrystal lcd (RS, EN, d4, d5, d6, d7); // LiquidCrystal lcd(8, 9, 4, 5, 6, 7); also works, without declaring the variables as above. The variant used in the code does not work without declaration.

void setup() { // put your setup code here, to run once:

  lcd.begin(16, 2); // initialize the interface on the LCD screen and specify the dimensions in width and height. 16 is the number of columns, 2 is the number of rows

  lcd.setCursor(0,0); // set the location at which subsequent text written to the LCD will be displayed; 0 is the starting point for column and row; in this case, the cursor is set in the first column and first row

  lcd.print("How do you feel?"); // print the text to the display. in this case, the text is on the first column and first row, as it was set earlier in lcd.setCursor(0,0);

  lcd.setCursor(0,1); // set the location at which subsequent text written to the LCD will be displayed; 0 is the starting point for column and row; in this case, the cursor is set in the first column and second row

  lcd.print("I feel:"); // print the text to the display. in this case, the text is on the first column and second row, as it was set earlier in lcd.setCursor(0,1);



 // make custom characters
 byte thrilled[8] = { // make a heart character of 8 bits
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};


byte happy[8] = { // make a smiley chararacter of 8 bits
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};

byte sad[8] = { // make a sad character of 8 bits
    0b00000,
    0b00000,
    0b01010,
    0b00000,
    0b00000,
    0b01110,
    0b10001,
    0b00000
};

byte surprised[8] = { // make a surprised character of 8 bits
    0b11011,
    0b00000,
    0b01010,
    0b00000,
    0b11111,
    0b10001,
    0b11111,
    0b00000
};

byte playful[8] = { // make a playful character of 8 bits
    0b00000,
    0b00000,
    0b01010,
    0b00000,
    0b00000,
    0b11111,
    0b10001,
    0b01110
};

  // create a new character
  lcd.createChar(0, thrilled); // create character 0 with the correspondent character data, which is named thrilled
  // create a new character
  lcd.createChar(1, happy); // create character 1 with the correspondent character data, which is named happy
  // create a new character
  lcd.createChar(2, sad); // create character 2 with the correspondent character data, which is named sad
  // create a new character
  lcd.createChar(3, surprised); // create character 3 with the correspondent character data, which is named surprised
  // create a new character
  lcd.createChar(4, playful); // create character 4 with the correspondent character data, which is named playful
}


void loop() { // put your main code here, to run repeatedly:
  int x; // declare x as an integer variable
  x = analogRead (0); // analog reading of pin A0
  lcd.setCursor(10,1); // set the cursor at the 11th column on the second row; take into account that 0 is the starting point
  if (x < 50) { // right button is pressed
    lcd.write(byte(0)); // right = thrilled
  }
  else if (x < 195) { // up button is pressed
    lcd.write (byte(1)); // up = happy
  }
  else if (x < 380){ // down button is pressed
    lcd.write (byte(2)); // down =  sad
  }
  else if (x < 590){ // left button is pressed
    lcd.write (byte(3)); // left = surprised
  }
  else if (x < 790){ // select button is pressed
    lcd.write (byte(4)); // select = playful
  }
}
Enter fullscreen mode Exit fullscreen mode

Credits:

arduino Article's
30 articles in total
Favicon
ESP32 Weather Dashboard with a WiFi Menu
Favicon
Broadcom APDS η³»εˆ—ζ™Άη‰‡
Favicon
Matter protocol on a budget
Favicon
Ulanzi TC001 - ESP32 Programming / Custom Arduino firmware
Favicon
Building a Security System, with motion detection and time based settings using Arduino
Favicon
Blueprint[1]: Arduino IoT Cloud x Blynk Cloud Integration
Favicon
A Code for Monitoring Temperature and Humidity with Arduino - Made by Gollum...
Favicon
How to Build a Line Follower Robot with Arduino
Favicon
Talk about binary search and its application on Arduino
Favicon
How I Automated a Greenhouse with IoT: The AgriSense Story
Favicon
Training portal to learn about XSS defenses and Arduino
Favicon
IRRemote 程式庫搭配 Adafruit_NeoPoxel η¨‹εΌεΊ«ηš„ε•ι‘Œ
Favicon
De[v]log#5: Arduino Cloud & Blynk Integration
Favicon
Home Automation System with Arduino and C++
Favicon
Automating Arduino Library Deployment with GitHub Actions: Version Validation, Pull Requests, and Release Automation
Favicon
Arduino Serial.parseInt ε‡½εΌηš„ι‹δ½œζ–ΉεΌ
Favicon
Implementing I2C for the ATtiny85
Favicon
Beyond the Blinky LED: Building a Command Interpreter for Microcontrollers
Favicon
η”¨η¨‹εΌζŽ§εˆΆ Arduino UNO R4 WiFi ηš„ TX/RX ζŒ‡η€Ίη‡ˆ
Favicon
Unlock Efficient Coding: Master Embedded Systems with Finite State Machines
Favicon
LCD 1602 Keypad Shield: How do you feel?
Favicon
the LivinGrimoire software design pattern
Favicon
Curso de Arduino, Marketing Digital e Outros Gratuitos Da UFSCar
Favicon
reading temperature and humidity data from dht11 sensor with arduino
Favicon
Connecting an Arduino MKR WiFi 1010 to AWS IoT Core
Favicon
Vending Machine Controller
Favicon
SmartRobot FollowLine & IoT
Favicon
PequeΓ±o tutorial sobre Arduino
Favicon
Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter β€” Write Your First Program
Favicon
Controlling a 28BYJ-48 Stepper Motor with Arduino: A Step-by-Step Guide

Featured ones: