#include <Keypad.h>
#include <ESP32Servo.h>
#define SERVO_PIN 13 // Servo signal pin
Servo myservo;
// 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] = {19, 18, 5, 17}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {16, 4, 2, 15}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(115200);
myservo.attach(SERVO_PIN);
myservo.write(0); // start position
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.print("Key Pressed: ");
Serial.println(key);
// Example control: map keys to servo angles
switch (key) {
case '1': myservo.write(0); break;
case '2': myservo.write(45); break;
case '3': myservo.write(90); break;
case '4': myservo.write(135); break;
case '5': myservo.write(180); break;
default: break;
}
}
}
//keypad predefined pins
//r1-esp19
//r2-esp18
//r3-esp5
//r4-esp17
//c1-esp16
//c2-esp4
//c3-esp2
//c4-esp15
//for servo pin connection
//pmw-esp13
//vcc-5V
//gnd-GND.1