Task: 1 Write A Sketch To Interface Arduino With A 3 X 4 Matrix Keypad. The Display of The Pressed Key Should Be Displayed On The LCD. Code
Task: 1 Write A Sketch To Interface Arduino With A 3 X 4 Matrix Keypad. The Display of The Pressed Key Should Be Displayed On The LCD. Code
Task: 1 Write A Sketch To Interface Arduino With A 3 X 4 Matrix Keypad. The Display of The Pressed Key Should Be Displayed On The LCD. Code
Write a sketch to interface Arduino with a 3 x 4 Matrix Keypad. The display of the
pressed key should be displayed on the LCD.
Code:
#include <LiquidCrystal.h>
#include <Keypad.h>
char keys[ROWS][COLS] =
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
void setup()
Serial3.begin(9600);
lcd.begin(16, 2);
void loop()
if (key)
{
Serial3.println(key);
lcd.print(key);
}
Circuit:
Task:2
Write a sketch that works as security keypad lock. Set any password. If the input
password matches with the set password, Green LED should glow, otherwise Red
LED will glow.
Code:
#include <Keypad.h>
int position = 0;
char keys[rows][cols] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
int greenPin = 9;
void setup()
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
setLocked(true);
void loop()
position = 0;
setLocked(true);
if (key == secretCode[position])
position ++;
if (position == 4)
{
setLocked(false);
delay(100);
if (locked)
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
else
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
}
Circuit:
Exercise:
Write a sketch to control the LEDs based on their Labelled Number. (Take input
from Keypad and there are 10 LED’s in all labelled from 0 to 9)
Code:
#include <Keypad.h>
int LED0 = 8;
int LED1 = 9;
char keys[rows][cols] =
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
void setup()
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
pinMode(LED8, OUTPUT);
pinMode(LED9, OUTPUT);
void loop()
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,HIGH);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,HIGH);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,HIGH);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
}
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,HIGH);
digitalWrite(LED9,LOW);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,HIGH);
}
Circuit: