This circuit is designed to interface an Arduino UNO R4 WiFi with an I2C LCD 16x2 Screen and a 4x4 Membrane Matrix Keypad. The Arduino serves as the central processing unit, controlling the LCD display and reading inputs from the keypad. The LCD is used to display messages to the user, such as prompts for password entry and access status. The keypad allows the user to input a password. The system is programmed to compare the entered password with a predefined password and display whether access is granted or denied.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Initialize the LCD
LiquidCrystal_I2C lcd(0x3C, 16, 2);
// Define the password
const String password = "DCBA";
String input = "";
// Keypad setup
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
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}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Connect to the column pinouts of the keypad
// Create the Keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == '#') {
if (input == password) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access Granted");
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Incorrect Password");
}
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
input = "";
} else if (key == '*') {
input = "";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Password:");
} else {
input += key;
lcd.setCursor(0, 1);
lcd.print(input);
}
}
}
This code initializes the LCD and keypad, then enters a loop where it waits for a keypress. When a key is pressed, it is added to the input string. If the '#' key is pressed, the input string is compared to the predefined password. If the password matches, "Access Granted" is displayed; otherwise, "Incorrect Password" is shown. The '*' key clears the current input. The LCD displays prompts and feedback based on the user's input.