mahdieh lotfollahpour
Published © GPL3+

Keypad

A simple Arduino-based authentication system that sends keypad input to a Windows Forms app via serial and verifies the password.

BeginnerFull instructions provided2 hours91
Keypad

Things used in this project

Story

Read more

Code

Keypad

Arduino
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

String password = "1234";  
String input = "";

int redLed = 13;
int greenLed = 11;
int buzzer = 12;

void setup() {
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  char key = keypad.getKey();
  if (key) {
    if (key == '#') {
      Serial.println(input);

      if (input == password) {
        digitalWrite(redLed, HIGH);
        digitalWrite(greenLed, LOW);
        digitalWrite(buzzer, LOW);
      } else {
        digitalWrite(redLed, LOW);
        digitalWrite(greenLed, HIGH);
        digitalWrite(buzzer, HIGH);
      }
      
      delay(2000);
      digitalWrite(redLed, LOW);
      digitalWrite(greenLed, LOW);
      digitalWrite(buzzer, LOW);
      input = "";
      
    } else if (key == '*') {
      input = "";
    } else {
      input += key;
      
    }
//    Serial.println(input);
  
  }
}

Credits

mahdieh lotfollahpour
3 projects • 0 followers

Comments