Arduino Code:
  1.  
  2. #include "Password.h"
  3. #include "Keypad.h"
  4. #include "Wire.h"
  5.  
  6.  
  7. #define REMOTE_LED_PIN 113 // Pin 2 on remote
  8.  
  9.  
  10. Password password = Password( "123");
  11.  
  12. const byte ROWS = 4; // Four rows
  13. const byte COLS = 4; // Three columns
  14. // Define the Keymap
  15. char keys[ROWS][COLS] = {
  16. {'1','2','3','A'},
  17. {'4','5','6','B'},
  18. {'7','8','9','C'},
  19. {'F','0','E','D'}
  20. };
  21.  
  22. // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
  23. byte rowPins[ROWS] = { 2, 3, 4, 5 };
  24. // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
  25. byte colPins[COLS] = { 6, 7, 8, 9 };
  26.  
  27.  
  28. // Create the Keypad
  29. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  30.  
  31. void setup(){
  32.  
  33. //Serial.begin(9600);
  34. keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  35. pinMode(10,OUTPUT);
  36. pinMode(11,OUTPUT);
  37. pinMode(12,OUTPUT);
  38. pinMode(13,OUTPUT);
  39. for(int i=0;i<=6;i++)
  40. {
  41. digitalWrite(11,HIGH);digitalWrite(10,HIGH);
  42. delay(5);
  43. digitalWrite(11,LOW);digitalWrite(10,LOW);
  44. }
  45. Wire.begin();
  46. }
  47.  
  48. void loop(){
  49. keypad.getKey();
  50. }
  51.  
  52. //take care of some special events
  53. void keypadEvent(KeypadEvent eKey){
  54. switch (keypad.getState()){
  55. case PRESSED:
  56. //Serial.print("Pressed: ");
  57. //Serial.println(eKey);
  58. switch (eKey){
  59. case 'F': checkPassword(); break;
  60. case 'E': password.reset(); break;
  61. default: password.append(eKey);
  62. }
  63. }
  64. }
  65.  
  66. void checkPassword(){
  67. if (password.evaluate()){
  68. //Serial.print("Success");
  69. digitalWrite(11,HIGH); //Green Light ON
  70. digitalWrite(10,LOW); //Red Light OFF
  71. expansionWrite(113,HIGH);
  72. //Add code to run if it works
  73.  
  74. digitalWrite(12,HIGH);//These Lines will Rotate the Motor
  75. digitalWrite(13,LOW); //in Clockwise Direction
  76.  
  77. delay(1000); //Delay between the door opening and closing
  78.  
  79. digitalWrite(11,LOW); //Green LED OFF
  80. digitalWrite(10,LOW); //Red LED OFF
  81.  
  82. digitalWrite(12,LOW);//These lines will rotate the
  83. digitalWrite(13,HIGH); //motor anticlockwise.
  84.  
  85. delay(1000);
  86.  
  87. digitalWrite(12,LOW);//These lines will rotate the
  88. digitalWrite(13,LOW); //motor anticlockwise.
  89.  
  90.  
  91. }else{
  92. //Serial.print("Wrong");
  93. digitalWrite(10,HIGH); //Red LED ON
  94. digitalWrite(11,LOW);
  95.  
  96. expansionWrite(113,LOW);
  97. //add code to run if it did not work
  98. delay(500);
  99. digitalWrite(11,LOW); //Red LED OFF
  100. digitalWrite(10,LOW);
  101. }
  102. }
  103.  
  104. void expansionWrite(int pin, int value)
  105. {
  106. pin = pin-100; // substracts 100 so it maps to the real ports on the expansion arduino
  107. Wire.beginTransmission(2); // transmit to device #2
  108. Wire.write(pin); // sends one byte stating the pin to be addressed
  109. Wire.write(value); // sends the value to be transmitted to the pin selected
  110. Wire.endTransmission(); // stop transmitting
  111. }
  112.  
  113. #define REMOTE_LED_PIN 113 // Pin 2 on remote
  114. Password password = Password( "123");
  115. const byte ROWS = 4; // Four rows
  116. const byte COLS = 4; // Three columns
  117. // Define the Keymap
  118. char keys[ROWS][COLS] = {
  119. {'1','2','3','A'},
  120. {'4','5','6','B'},
  121. {'7','8','9','C'},
  122. {'F','0','E','D'}
  123. };
  124. // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
  125. byte rowPins[ROWS] = { 2, 3, 4, 5 };
  126. // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
  127. byte colPins[COLS] = { 6, 7, 8, 9 };
  128. // Create the Keypad
  129. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  130. void setup(){
  131. //Serial.begin(9600);
  132. keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  133. pinMode(10,OUTPUT);
  134. pinMode(11,OUTPUT);
  135. pinMode(12,OUTPUT);
  136. pinMode(13,OUTPUT);
  137. for(int i=0;i<=6;i++)
  138. {
  139. digitalWrite(11,HIGH);digitalWrite(10,HIGH);
  140. delay(5);
  141. digitalWrite(11,LOW);digitalWrite(10,LOW);
  142. }
  143. Wire.begin();
  144. }
  145. void loop(){
  146. keypad.getKey();
  147. }
  148. //take care of some special events
  149. void keypadEvent(KeypadEvent eKey){
  150. switch (keypad.getState()){
  151. case PRESSED:
  152. //Serial.print("Pressed: ");
  153. //Serial.println(eKey);
  154. switch (eKey){
  155. case 'F': checkPassword(); break;
  156. case 'E': password.reset(); break;
  157. default: password.append(eKey);
  158. }
  159. }
  160. }
  161. void checkPassword(){
  162. if (password.evaluate()){
  163. //Serial.print("Success");
  164. digitalWrite(11,HIGH); //Green Light ON
  165. digitalWrite(10,LOW); //Red Light OFF
  166. expansionWrite(113,HIGH);
  167. //Add code to run if it works
  168.  
  169. digitalWrite(12,HIGH);//These Lines will Rotate the Motor
  170. digitalWrite(13,LOW); //in Clockwise Direction
  171.  
  172. delay(1000); //Delay between the door opening and closing
  173.  
  174. digitalWrite(11,LOW); //Green LED OFF
  175. digitalWrite(10,LOW); //Red LED OFF
  176.  
  177. digitalWrite(12,LOW);//These lines will rotate the
  178. digitalWrite(13,HIGH); //motor anticlockwise.
  179.  
  180. delay(1000);
  181.  
  182. digitalWrite(12,LOW);//These lines will rotate the
  183. digitalWrite(13,LOW); //motor anticlockwise.
  184.  
  185.  
  186. }else{
  187. //Serial.print("Wrong");
  188. digitalWrite(10,HIGH); //Red LED ON
  189. digitalWrite(11,LOW);
  190.  
  191. expansionWrite(113,LOW);
  192. //add code to run if it did not work
  193. delay(500);
  194. digitalWrite(11,LOW); //Red LED OFF
  195. digitalWrite(10,LOW);
  196. }
  197. }
  198. void expansionWrite(int pin, int value)
  199. {
  200. pin = pin-100; // substracts 100 so it maps to the real ports on the expansion arduino
  201. Wire.beginTransmission(2); // transmit to device #2
  202. Wire.write(pin); // sends one byte stating the pin to be addressed
  203. Wire.write(value); // sends the value to be transmitted to the pin selected
  204. Wire.endTransmission(); // stop transmitting
  205. }
  206.