0% found this document useful (0 votes)
9 views

session 6arduino

The document discusses the importance of keypads as input devices for microcontrollers, highlighting their efficiency in reducing the number of required input pins through a matrix arrangement. It provides examples of keypad types, specifically the 4x4 matrix keypad, and includes sample code for interfacing with a keypad and an infrared sensor. Additionally, it outlines a task involving the use of a keypad to receive user input and display the sum on an LCD.

Uploaded by

anasmostafa801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

session 6arduino

The document discusses the importance of keypads as input devices for microcontrollers, highlighting their efficiency in reducing the number of required input pins through a matrix arrangement. It provides examples of keypad types, specifically the 4x4 matrix keypad, and includes sample code for interfacing with a keypad and an infrared sensor. Additionally, it outlines a task involving the use of a keypad to receive user input and display the sum on an LCD.

Uploaded by

anasmostafa801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Prepared by:

Esraa taha ali


keypad
Why we need keypad ?
Many application requires large number of keys connected to a
computing system.
Example includes a PC keyboard, Cell Phone keypad and
Calculators. If we connect a single key to MCU, we just connect
it directly to i/o line. But we cannot connect, say 10 or 100 keys
directly MCUs i/o. Because It will eat up precious i/o line.
Why we need keypad ?
Keypad is most widely used input device to provide input from
the outside world to the microcontroller. The keypad makes an
application more users interactive.
types of keypad
The are two types of keypad 4×3 & 4×4 membrane
keypad
The importance of keypad

If you had used 16 individual push buttons, you would have


required 17 input pins (one for each key and a ground pin) in
order to make them work. However, with matrix arrangement,
you only need 8 microcontroller pins (4-columns and 4-rows) to
scan through the pad.
keypad
We want to avoid all these troubles so we use some clever
technique. The technique is called matrix keypad
we will focus on( 4×4 Matrix Keypad). In this technique keys
are connected in a matrix
(row/column) style.
.
4×4 Matrix Keypad
4×4 Matrix Keypad Interfacing
Hello keypad
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);}
void loop(){
char key = keypad.getKey();// Read the key
if (key){
Serial.print("Key Pressed : ");
Serial.println(key);}}
Tinkercad design
task1:

Write a program to receive two values


from user using keypad and displayed
the sum of values on lcd
code
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11, 5, 4, 3, 2);
char x=0,y=0;
int X,Y;
int sum(int A,int B);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {A0,A1,A2,A3};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
lcd.begin(16, 2);
lcd.clear();}
void loop(){
lcd.clear();
lcd.print("enter first num:");
do{
x= keypad.getKey();}while(x==0);
X=x-48;
lcd.clear();
lcd.print("enter second num:");
do{
y= keypad.getKey();}while(y==0);
Y=y-48;
lcd.clear();
lcd.print(X);
lcd.print("+");
lcd.print(Y);
lcd.print("=");
lcd.print(sum(X,Y));
delay(1000);

}
int sum(int A,int B){
int y= A+B;
return y;

}
Tinker cad design
infrared sensor(IR)
An infrared sensor is an electronic device, that emits in order to
sense some obstacles of the surroundings. An IR sensor can measure
the heat of an object as well as detects the motion. These types of
sensors measures only infrared radiation.
infrared sensor(IR)
The basic concept of an Infrared Sensor which is used as Obstacle
detector is to transmit an infrared signal, this infrared signal bounces
from the surface of an object and the signal is received at the infrared
receiver.
Can an IR sensor detect humans?
The Passive Infrared (PIR) sensor is used to detect the presence of
human.
It detects the human using the infrared radiation radiated by the
human body. Every human radiates the infrared energy of specific
wavelength range. The absorbed incident radiation changes the
temperature of a material.
code
void setup() {
pinMode(13,OUTPUT);
pinMode(3,INPUT);
Serial.begin(9600); }
void loop() { if (digitalRead(3)== HIGH)
{ digitalWrite(13,HIGH);
delay(10); }
else { digitalWrite(13,LOW);
delay(10); } }
Tinkercad design
Task
design the pervious project in proteus.

library of sensor for proteus .


https://drive.google.com/file/d/11QUPdasuD0il
PT5zZ7ufyZKd5sUWPFO7/view?usp=sharing

You might also like