#include const char* password = "427"; // Change the password here, just pick any 3 numbers int position = 0; 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] = {8, 7, 6, 9}; byte colPins[COLS] = {5, 4, 3, 2}; Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); int RedpinLock = 12; int GreenpinUnlock = 13; int relayPin = 10; // Define the pin connected to the relay module void setup() { pinMode(RedpinLock, OUTPUT); pinMode(GreenpinUnlock, OUTPUT); pinMode(relayPin, OUTPUT); LockedPosition(true); // Initially, set to locked position } void loop() { char key = keypad.getKey(); if (key == '*' || key == '#') { position = 0; LockedPosition(true); } if (key == password[position]) { position++; } if (position == 3) { LockedPosition(false); } delay(100); } void LockedPosition(int locked) { if (locked) { digitalWrite(RedpinLock, HIGH); digitalWrite(GreenpinUnlock, LOW); digitalWrite(relayPin, LOW); // Deactivate the relay } else { digitalWrite(RedpinLock, LOW); digitalWrite(GreenpinUnlock, HIGH); digitalWrite(relayPin, HIGH); // Activate the relay } }