Micro 131L Lab Experiment 10 11 LCD Keypad and RTC in Arduino Board
Micro 131L Lab Experiment 10 11 LCD Keypad and RTC in Arduino Board
School of Engineering
Grade
SN, FN MI _______________________
Objectives:
Materials:
void setup()
{
init_device();
}
void loop()
{
intro_display();
display_temp(fahr_temp, cel_temp);
void init_device()
{
//initialize LCD size
MyTemp_LCD.begin(COLS, ROWS);
//clear LCD text display
MyTemp_LCD.clear();
//display "MICRO131L Lab 10" at 0,0
MyTemp_LCD.setCursor(COL1, ROW1);
MyTemp_LCD.print("MICRO131L Lab 10");
//display "Design Apps 10.1" at 0,1
MyTemp_LCD.setCursor(COL1, ROW2);
MyTemp_LCD.print("Design Apps 10.1");
//wait for 2s
LONG_DEL;
//clear LCD text display
MyTemp_LCD.clear();
}
void intro_display()
{
MyTemp_LCD.clear();
MyTemp_LCD.setCursor(COL1, ROW1);
MyTemp_LCD.print("TEMP. MONITORING");
MyTemp_LCD.setCursor(COL2, ROW2);
MyTemp_LCD.print("VERSION 3");
SHORT_DEL;
}
This program will demonstrate how to adjust the time and date generated
by DS1307 RTC (Real-time Clock) chip using push button switch in 16:2 LCD
module.
//macro constants
#define INIT_PARAM (0)
#define HR_PARAM (0)
#define MIN_PARAM (1)
#define DAY_PARAM (2)
#define MON_PARAM (3)
#define YR_PARAM (4)
#define INIT_HR (0)
#define MAX_HR (23)
#define INIT_MIN (0)
#define MAX_MIN (59)
#define INIT_DAY (1)
#define MAX_DAY (31)
#define INIT_MON (1)
#define MAX_MON (12)
#define INIT_YR (0)
#define MAX_YR (99)
void setup()
{
//Setup PB switches as input with enable pull-up resistance
pinMode(EDIT_PB_SW, INPUT_PULLUP);
pinMode(SET_PB_SW, INPUT_PULLUP);
//Setup the LCD columns and rows
Lcd_RTC.begin(COLS, ROWS);
//start i2c bus protocol for RTC pins
Wire.begin();
display_intro();
}
char Time[] = "TIME: : : ";
char Calendar[] = "DATE: / /20 ";
byte next_param, second, minute, hour, date, month, year;
void display_intro()
{
Lcd_RTC.setCursor(COL, ROW1);
Lcd_RTC.print(Time); //Display time
Lcd_RTC.setCursor(COL, ROW2);
Lcd_RTC.print(Calendar); //Display calendar
}
while(true)
{
while(!digitalRead(SET_PB_SW))
{ //If SET_PB_SW (pin 9) is pressed
parameter++;
//If hours > 23 ==> hours = 0
if(next_param == HR_PARAM && parameter > MAX_HR)
parameter = INIT_HR;
//If minutes > 59 ==> minutes = 0
if(next_param == MIN_PARAM && parameter > MAX_MIN)
parameter = INIT_MIN;
//If date > 31 ==> date = 1
if(next_param == DAY_PARAM && parameter > MAX_DAY)
parameter = INIT_DAY;
//If month > 12 ==> month = 1
if(next_param == MON_PARAM && parameter > MAX_MON)
parameter = INIT_MON;
//If year > 99 ==> year = 0
if(next_param == YR_PARAM && parameter > MAX_YR)
parameter = INIT_YR;
sprintf(disp_text,"%02u", parameter);
Lcd_RTC.setCursor(col_pos, row_pos);
Lcd_RTC.print(disp_text);
DISP_TEXT_DEL; //Wait 200ms
}
Lcd_RTC.setCursor(col_pos, row_pos);
Lcd_RTC.print(" "); //Display two spaces
blink_parameter();
sprintf(disp_text,"%02u", parameter);
Lcd_RTC.setCursor(col_pos, row_pos);
Lcd_RTC.print(disp_text);
blink_parameter();
if(!digitalRead(EDIT_PB_SW))
{ //If EDIT_PB_SW (pin 8) is pressed
next_param++; //Increament 'next_param' for the next parameter
return parameter; //Return parameter value and exit
}
}
}
void loop()
{
if(!digitalRead(EDIT_PB_SW))
{
//If EDIT_PB_SW (pin 8) is pressed then
next_param = INIT_PARAM; //set next_param to hour
hour = edit(5, 0, hour); //store hour at 5,0 of LCD
minute = edit(8, 0, minute); //store minutes at 8,0 of LCD
date = edit(5, 1, date); //store day at 5,1 of LCD
month = edit(8, 1, month); //store month at 8,1 of LCD
year = edit(13, 1, year); //store year at 13,1 of LCD
This program will demonstrate how to use Keypad and Password Arduino
libraries in keypad-controlled door security. This security lock consists of a 4 x 3
telephone keypad module, LED module, and Arduino as microcontroller.
A. Header File – passkey_door.h
//macro for LED indicator pins
#define LED_READY (11)
#define LED_LOCK (12)
#define LED_UNLOCK (13)
//macro for keypad size
#define MAX_ROW (4)
#define MAX_COL (3)
//macro for keypad row pins
#define ROW0 (5)
#define ROW1 (6)
#define ROW2 (7)
#define ROW3 (8)
//macro for keypad column pins
#define COL0 (2)
#define COL1 (3)
#define COL2 (4)
//macro constant
#define MIN_CNT (0)
#define MAX_CNT (3)
//macro delay routines
#define KEY_DEL delay(10)
#define DOOR_DEL delay(1000)
//Connect doorKey ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {ROW0, ROW1, ROW2, ROW3};
//Connect doorKey COL0, COL1 and COL2 to these Arduino pins
byte colPins[COLS] = {COL0, COL1, COL2};
void loop()
{
keypadReady();
doorKey.getKey();
}
void keypadReady()
{
digitalWrite(LED_LOCK, HIGH);
digitalWrite(LED_UNLOCK, LOW);
switch (eKey)
{
case '*': checkPassword(); break;
case '#': doorPass.reset(); break;
default: doorPass.append(eKey);
}
}
}
void checkPassword()
{
if (doorPass.evaluate())
{
digitalWrite(LED_READY, LOW);
digitalWrite(LED_LOCK, LOW);
digitalWrite(LED_UNLOCK, HIGH);
DOOR_DEL;
doorPass.reset();
}
else
{
digitalWrite(LED_READY, LOW);
digitalWrite(LED_LOCK, HIGH);
digitalWrite(LED_UNLOCK, LOW);
}
}
PIN CONFIGURATION
1k
RV1
1
VSS
2
SCHEMATIC DIAGRAM
LCD1
AREF VDD
3
VEE
13
PB5/SCK
12 4
16:2 LCD Module
PB4/MISO RS
RESET 11 5
~PB3/MOSI/OC2A RW
10 6
~ PB2/SS/OC1B E
9
~ PB1/OC1A
8 7
PB0/ICP1/CLKO D0
8
D1
1121
7 9
PD7/AIN1 D2
6 10
A0 ~ PD6/AIN0 D3
PC0/ADC0 5 11
A1 ~ PD5/T1 D4
ATMEGA328P-PU
PC1/ADC1 4 12
A2 PD4/T0/XCK D5
PC2/ADC2 3 13
A3 ~ PD3/INT1 D6
ANALOG IN
PC3/ADC3 2 14
A4 PD2/INT0 D7
PC4/ADC4/SDA 1
DIGITAL (~PWM)
A5 TX PD1/TXD
PC5/ADC5/SCL 0
RX PD0/RXD
ARD1
TEMPERATURE SENSOR
ARDUINO UNO R3
3
VCC
89.0
VOUT
LM34
SET_PB
VCC
10k
R3
EDIT_PB
VCC
10k
R4
1
VSS
2
LCD1
AREF VDD
3
VEE
13
PB5/SCK
12 4
16:2 LCD Module
PB4/MISO RS
RESET 11 5
~PB3/MOSI/OC2A RW
10 6
~ PB2/SS/OC1B E
9
~ PB1/OC1A
8 7
PB0/ICP1/CLKO D0
8
1121 D1
7 9
PD7/AIN1 D2
6 10
A0 ~ PD6/AIN0 D3
PC0/ADC0 5 11
A1 ~ PD5/T1 D4
ATMEGA328P-PU
PC1/ADC1 4 12
A2 PD4/T0/XCK D5
PC2/ADC2 3 13
A3 ~ PD3/INT1 D6
ANALOG IN
PC3/ADC3 2 14
A4 PD2/INT0 D7
PC4/ADC4/SDA 1
DIGITAL (~PWM)
A5 TX PD1/TXD
PC5/ADC5/SCL 0
RX PD0/RXD
VCC
ARD1
ARDUINO UNO R3
10k
R1
VCC
3
7
5
6
3.0V
BAT1
10k
U1
R2
SCL
SDA
SOUT
DS1307
VBAT X2
X1
2
1
2 1
X1
CRYSTAL
B
A
D
C
1
7
4
1
2
0
8
5
2
3
#
9
6
3
~ PB2/SS/OC1B
9
~ PB1/OC1A
8
UNLOCK
PB0/ICP1/CLKO
microcontrolandos.blogspot.com
1121
7
PD7/AIN1
6
A0 ~ PD6/AIN0
PC0/ADC0 5
A1 ~ PD5/T1
ATMEGA328P-PU
PC1/ADC1 4
D2
A2 PD4/T0/XCK
PC2/ADC2 3
LOCK
A3 ~ PD3/INT1
ANALOG IN
PC3/ADC3 2
A4 PD2/INT0
PC4/ADC4/SDA 1
DIGITAL (~PWM)
A5 TX PD1/TXD
PC5/ADC5/SCL 0
RX PD0/RXD
D3
DUINO1
ARDUINO UNO R3
DATA RESULTS
Note: Screen shots or captured outputs per program (at least outputs per
program)
DATA ANALYSIS / OBSERVATION
NOTE: Discussion must be based on the data gathered from data results or
observation supported by review of literature with proper reference or author in-
text citation in APA format. Do not copy-paste instead paraphrase it. Data analysis
must be minimum of 2 pages.
QUESTIONS AND ANSWERS
1. Discuss the principles how LCD, GLCD, and OLED display can be
controlled by Arduino microcontroller. Provide snip of code for each.
2. Discuss how I2C protocol works in real-time clock (RTC).
3. Given the system process flow below, design a schematic diagram, create
and simulate a sketch program for a keypad vault security lock in LCD
display.
Books:
Electronic Books:
Cooper, D. (2009, March 31). Native ant may stop toad in its tracks. ABC
Science. Retrieved August 15, 2017 from
http://www.abc.net.au/science/articles/
2009/03/31/2530686.htm?site=science&topic=latest
Print Journals:
Electronic Journals: