#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 7, 6, 5, 4 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 11, 10, 9, 8 }; // Pins connected to R1, R2, R3, R4
Keypad mykeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27,16,2);
#define pinRelay 2
void setup() {
pinMode(pinRelay, OUTPUT);
lcd.begin(16,2);
lcd.clear();
lcd.backlight();
}
void loop() {
char keyPress = mykeypad.getKey();
if (keyPress) {
lcd.print(keyPress);
if (keyPress=='*') {
digitalWrite(pinRelay, HIGH);
}
if (keyPress=='#') {
digitalWrite(pinRelay, LOW);
}
}
}