Password Protected LCD (Arduino)

by LoganPaxton in Circuits > Arduino

118 Views, 1 Favorites, 0 Comments

Password Protected LCD (Arduino)

Screenshot 2024-10-02 7.52.48 PM.png

Today, we will be making a password protected LCD. I will walk you through all of the code, and wiring.

Supplies

  1. Arduino (I'm using an Arduino UNO R3)
  2. x12 Jumper wires
  3. 4x4 Keypad (You can use a 3x4)
  4. I2C 16x2 LCD (This tutorial will not cover non-I2C LCDs)

Note: You can use something online like Tinkercad's circuit designer

Keypad

Screenshot 2024-10-02 7.58.36 PM.png

First, you want to wire up the keypad. Pretty much, you want to start at D9, and keep going until you run out of slots on the keypad.

LCD

Screenshot 2024-10-02 8.04.58 PM.png

Now, we want to wire up our LCD. This is quite simple. Wire GND to the GND pin, VCC to the 5V Pin. Now, the SDA and the SCL pins don't have a label, but SCL is the closest to the reset button (on the R3), and SDA is right beside SCL.

Coding

Now, before we can code the keypad and LCD. We first need to find out what the LCD's address is, mine is 0x20 although it can vary between boards. To find out what your address is, you can get the code from https://playground.arduino.cc/Main/I2cScanner/, and run that. Now, we can get to coding.


Here is the code for the whole thing.

#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

const byte ROWS = 4; // Set to the amount of rows you have
const byte COLS = 4; // Set to the amount of columns you have

char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'}, // Change if needed
{'4', '5', '6', 'B'}, // Change if needed
{'7', '8', '9', 'C'}, // Change if needed
{'*', '0', '#', 'D'} // Change if needed
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

LiquidCrystal_I2C lcd(0x20, 16, 2); // Replace 0x20 with the address you have

void setup(){
lcd.backlight();
lcd.init();
}

String code = "";

void loop(){
char customKey = customKeypad.getKey();
if (customKey){
lcd.clear();
lcd.setCursor(0, 0);
code += customKey;
// Feel free to change the 4 to any number, it is just the max numbers of chars on the screen
if (code.length() == 4) {
lcd.print(code);
code = "";
delay(500);
lcd.clear();
}
lcd.print(code);
}
}

Finished!

And there you go, you can add the password protection logic if you want!