Arduino Keypad Code
Arduino Keypad Code
*/
#include <Keypad.h>
enum SYSTEM_STATUS{
LOCKED // 0
UNLOCKED // 1
};
String input;
int PIR_value ;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {2,3,4,5}; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to the
byte colPins[ROWS] = {6,7,8,9}; // Connect keypad COL0, COL1, COL2 and COL3 to the Galileo
// Keypad object that uses pins 2, 3, 5, 6 as row pins, and 6, 7, 8, 9 as column pins.
// This keypad has 4 rows and 4 columns, resulting in 16 keys.
void setup()
Serial.begin(115200);
pinMode(PIR_sensor, INPUT);
pinMode(led_white, OUTPUT);
pinMode(led_green , OUTPUT);
digitalWrite(led_white, HIGH); // The default is system locked... so, the LED must be HIGH
digitalWrite(led_green , LOW);
void loop()
input += key;
Serial.print("key:");
Serial.println(key);
/* this function is only called when the PIN code typed matches the secret PIN code and inverts the
system logic. It means if the system was LOCKED it will be UNLOCKED and vice versa.
*/
void updateLEDStatus()
if (currentStatus == LOCKED)
currentStatus = UNLOCKED;
Serial.println("SYSTEM UNLOCKED");
else
currentStatus = LOCKED;
Serial.println("SYSTEM LOCKED");
digitalWrite(led_red,LOW);
switch (keypad.getState())
delay(500);
digitalWrite(ledPin, !digitalRead(led_white));
Serial.println(input);
if (input == password)
{
updateLEDStatus();
input = "";
break;
break;