Code for arduino connected to the Keypad (Tx) is :
#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
'1','2','3' }
,
{
'4','5','6' }
,
{
'7','8','9' }
,
{
'*','0','#' }
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {
5,4,3,2 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {
6,7,8 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledpin 13
void setup()
{
Serial.begin(9600);
}
void loop()
{
char key = kpd.getKey();
if(key) // Check for a valid key.
{
Serial.print(key);
}
}
we need arduino Keyboard library to compile the above code, can be found http://playground.arduino.cc/code/keypad
Arduino Connected to the Virtual Terminal(Rx) is:
#define password 123
#include<SoftwareSerial.h>
SoftwareSerial mySerial(10,11);//10-Rx 11-Tx
char data_buffer[15];
boolean read_data = false;
byte index;
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
mySerial.println("welcome");
mySerial.println("please enter password with starting letter * and ending letter # like *123#");
}
void loop(){
if(Serial.available())
{
char input = Serial.read();
if (input == '*')
{
read_data = true;
index = 0;
}
else if(input == '#')
{
data_buffer[index] = 0;
read_data = false;
mySerial.print("the value value you entered is");
mySerial.println(atoi(data_buffer));
if (atoi(data_buffer) == password){
mySerial.println("password Matched");
}
else{
mySerial.println("wrong Password");
}
}
else
{
if(read_data)
{
data_buffer[index] = input;
index = index + 1;
}
}
}
}//end of loop
please see the video below to see how the schematic is done
No comments:
Post a Comment