/* This code works with 4x4 Keypad Matrix, LCD ic, IRF510N transistor and a push button * It's a lock where the transistor drives a solenoid lock you can open either with correct code * or by the push button from inside * The code can be changed directly by the keypad and doesn't require uploading code again * Code is stored in EEPROM * Refer to www.surtrtech.com for more details */ #include #include #include #define Solenoid 11 //Actually the Gate of the transistor that controls the solenoid #define O_Button 10 //Push Button #define I2C_ADDR 0x27 //I2C adress, you should use the code to scan the adress first (0x27) here #define BACKLIGHT_PIN 3 // Declaring LCD Pins #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 const byte numRows= 4; //number of rows on the keypad const byte numCols= 4; //number of columns on the keypad char keymap[numRows][numCols]= { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; char keypressed; //Where the keys are stored it changes very often char code[]= {'6','6','0','1'}; //The default code, you can change it or make it a 'n' digits one char code_buff1[sizeof(code)]; //Where the new key is stored char code_buff2[sizeof(code)]; //Where the new key is stored again so it's compared to the previous one short a=0,i=0,s=0,j=0; //Variables used later byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3 //if you modify your pins you should modify this too byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3 LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); void setup() { lcd.begin (16,2); lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); //Lighting backlight lcd.home (); lcd.print("Standby"); //What's written on the LCD you can change pinMode(Solenoid,OUTPUT); pinMode(O_Button,INPUT); // for(i=0 ; i