Arudino 1602 Keypad shield configuration
Amazon Purchase link: 1602 LCD Board Keypad Shield Blue Backlight for Arduino Robot
https://amzn.eu/d/hzUdw5K
1602 Arduino LCD Keypad Shield Features
Displaying information in electronic projects has always been the most compelling issue. There are various ways to display data. These screens can be so simple such as 7segments or LEDs, or they can be more fascinating such as LCDs. Using LCDs has always been one of the most popular ways to display information. LCDs are divided into two generic types: Characters and Graphics.
One of the most common, cheapest and simplest LCDs available is the character LCD. This LCD consists of several rows and columns. Letters and numbers are written in places created by rows and columns. For example, LCD character 16*2 has 2 rows and 16 columns. So it can display 32 characters.
Working with these LCDs is very simple and they have full compatibility with all microcontrollers and processor boards. For easier use of these LCDs, its 16x2model, including four keys for making the menu, is made as a Shield which is also compatible with Arduino boards.
How to Use Arduino LCD Keypad Shield
Arduino shiels is a user-friendly and simple shield. To use it you need to know its pinout and its connection to Arduino at first.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Manmohan Pal");
lcd.setCursor(0, 1);
lcd.print("Mob. 8989811397");
delay (1500);
lcd.clear();
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("Hello World");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
//--------------------------------------------------------------------------
Tutorial 2 # how to detect which key is pressed:
How to Read the Keys?
In this shield, all 4 keys are connected to the analog pin 0 to save on digital pins. So we should use ADC to read them. When you press a key, it returns a value to the A0 pin according to the internal resistive splitting circuit, which identifies the type of the key.
-----------------------------------------------------------------------
Code for button identification
#include <LiquidCrystal.h>
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
Serial.begin(9600);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("Manmohan Pal");
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue > 60 && sensorValue < 200 ){Serial.println("up button pressed "); lcd.setCursor(5, 1);lcd.print(" UP ");}
if (sensorValue > 200 && sensorValue < 400 ){Serial.println("down button pressed ");lcd.setCursor(5, 1);lcd.print("Down ");}
if (sensorValue > 400 && sensorValue < 600 ){Serial.println("left button pressed ");lcd.setCursor(5, 1);lcd.print("Left ");}
if (sensorValue == 0 ){Serial.println("right button pressed ");lcd.setCursor(5, 1);lcd.print("Right");}
if (sensorValue > 600 && sensorValue < 800 ){Serial.println("Select button pressed ");lcd.setCursor(5, 1);lcd.print(" Sel ");}
}
//--------------------------------------------------
Tutorial 3 # how to display RTC time on LCD Keypad Shield
1. download the above library zip file and unzip it using winrar or other software,
2. copy the extracted folder to the arduino/library/...
//------------------------------------------------
#include <LiquidCrystal.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
Serial.begin(9600);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("Manmohan Pal");
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
// When time needs to be re-set on a previously configured device, the
// following line sets the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
delay(1000);
lcd.clear();
}
void loop() {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC); // rtc.adjust(DateTime(now.year(),now.month(), now.day(), now.hour(), now.minute(), 0));
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
lcd.setCursor(0, 0);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(" ");
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue > 60 && sensorValue < 200 ){Serial.println("up button pressed "); lcd.setCursor(11, 1);lcd.print(" UP ") ;
rtc.adjust(DateTime(now.year(),now.month(), now.day(), (now.hour()+1), now.minute(), 0));}
if (sensorValue > 200 && sensorValue < 400 ){Serial.println("down button pressed ");lcd.setCursor(11, 1);lcd.print("Down ");
rtc.adjust(DateTime(now.year(),now.month(), now.day(), (now.hour()-1), now.minute(), 0));}
if (sensorValue > 400 && sensorValue < 600 ){Serial.println("left button pressed ");lcd.setCursor(11, 1);lcd.print("Left ");
rtc.adjust(DateTime(now.year(),now.month(), now.day(), now.hour(), (now.minute()-1), 0));}
if (sensorValue == 0 ){Serial.println("right button pressed ");lcd.setCursor(5, 1);lcd.print("Right");
rtc.adjust(DateTime(now.year(),now.month(), now.day(), now.hour(), (now.minute()+1), 0));}
if (sensorValue > 600 && sensorValue < 800 ){Serial.println("Select button pressed ");lcd.setCursor(11, 1);lcd.print(" Sel ");}
delay(1000);
}
//-----------------------------------------------------------------
No comments:
Post a Comment