Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I would like to introduce the Infrared Matrix Password Input System with Arduino, for more details:http://www.instructables.com/id/Infrared-Matrix-Password-Input-System-with-Arduino/
- the code for this system as following:
- #include <LiquidCrystal.h> //LCD library header files
- #include <IRremote.h>//Infrared library header files
- #include <Password.h> //Matrix keyboard password library header files
- #include <Keypad.h> //Matrix keyboard library header files
- #define uchar unsigned char
- #define uint unsigned int
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//Define the LCD1602 pin connection
- Password password = Password( "1234" );//Set up the matrix keyboard password
- int RECV_PIN = 7;//Infrared receiver tube feet
- const byte ROWS = 4; // Four rows
- const byte COLS = 4; // columns
- char keys[ROWS][COLS] =
- {
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };// Create the Keypad
- byte rowPins[ROWS] = { 31,33,35,37};// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
- byte colPins[COLS] = { 39,41,43,45};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
- Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
- //Initializes the internal keymap to be equal to userKeymap
- IRrecv irrecv(RECV_PIN);//Define a receiver input pin
- decode_results results;//Save the decoding of variables results
- int i=0;
- long code_1,code_2,code_3,code_4,code_5;
- void setup()
- {
- lcd.begin(16, 2);
- lcd.setCursor(4,0);
- lcd.print("welcome");
- lcd.setCursor(4,1);
- irrecv.enableIRIn(); // Start the receiver
- keypad.addEventListener(keypadEvent); //add an event listener for this keypad
- }
- void loop()
- {
- keypad.getKey();
- infrared();
- }
- void infrared()//Infrared password input
- {
- if (irrecv.decode(&results)) //Decoding is successful, the data in the results variables
- {
- if(results.value!=4294967295)//Whether the infrared remote control has been hold
- {
- if(i==0)
- {
- code_1=results.value;
- infrareddisplay(code_1);//LCD display the corresponding infrared buttons
- i=1;
- }
- else if(i==1)
- {
- code_2=results.value;
- infrareddisplay(code_2);
- i=2;
- }
- else if(i==2)
- {
- code_3=results.value;
- infrareddisplay(code_3);
- i=3;
- }
- else if(i==3)
- {
- code_4=results.value;
- infrareddisplay(code_4);
- i=4;
- }
- else if(i==4)
- {
- if(results.value==16748655)
- {
- infrared_password();
- }
- i=0;
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("welcome");
- lcd.setCursor(4,1);
- }
- }
- irrecv.resume(); // Receive the next value
- }
- }
- void infrared_password()//Infrared password comparison
- {
- if(code_1==16724175)//The first value is 1
- {
- if(code_2==16718055)//The second value of 2
- {
- if(code_3==16743045)//The third value is 3
- {
- if(code_4==16716015)//The fourth value is 4
- {
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("Success!");
- delay(2000);
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("welcome");
- lcd.setCursor(4,1);
- }
- else
- {
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("Wrong");
- delay(2000);
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("welcome");
- lcd.setCursor(4,1);
- }
- }
- else
- {
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("Wrong");
- delay(2000);
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("welcome");
- lcd.setCursor(4,1);
- }
- }
- else
- {
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("Wrong");
- delay(2000);
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("welcome");
- lcd.setCursor(4,1);
- }
- }
- else
- {
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("Wrong");
- delay(2000);
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("welcome");
- lcd.setCursor(4,1);
- }
- }
- void infrareddisplay(long x)//LCD display the corresponding infrared buttons
- {
- if(x==16738455)
- {
- lcd.print('0');
- }
- if(x==16724175)
- {
- lcd.print('1');
- }
- if(x==16718055)
- {
- lcd.print('2');
- }
- if(x==16743045)
- {
- lcd.print('3');
- }
- if(x==16716015)
- {
- lcd.print('4');
- }
- if(x==16726215)
- {
- lcd.print('5');
- }
- if(x==16734885)
- {
- lcd.print('6');
- }
- if(x==16728765)
- {
- lcd.print('7');
- }
- if(x==16730805)
- {
- lcd.print('8');
- }
- if(x==16732845)
- {
- lcd.print('9');
- }
- if(x==16748655)
- {
- infrared_password();
- }
- }
- void keypadEvent(KeypadEvent eKey)//Matrix keyboard password
- {
- switch (keypad.getState())
- {
- case PRESSED:
- lcd.print(eKey);
- switch (eKey)
- {
- case '#': checkPassword(); break;
- case '*': password.reset(); break;
- default: password.append(eKey);
- }
- }
- }
- void checkPassword()//Matrix keyboard password display
- {
- if (password.evaluate())
- {
- lcd.clear();
- lcd.setCursor(5,0);
- lcd.print("Success!");
- delay(2000);
- lcd.clear();
- lcd.setCursor(5,0);
- lcd.print("welcome");
- lcd.setCursor(5,1);
- }
- else
- {
- lcd.clear();
- lcd.setCursor(5,0);
- lcd.print("Wrong");
- delay(2000);
- lcd.clear();
- lcd.setCursor(5,0);
- lcd.print("welcome");
- lcd.setCursor(5,1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment