#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <Keypad.h>
Servo myservo;
const int ledYellow = 12; // LED connected to digital pin 12
const int pirYellow = 1; // PIR sensor connected to digital pin 1
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
const int numRows = 4;
const int numCols = 4;
char keys[numRows][numCols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_rows[numRows] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad
byte pin_column[numCols] = {5, 4, 3, 10}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, numRows, numCols);
void setup() {
Serial.begin(9600);
pinMode(ledYellow, OUTPUT);
pinMode(pirYellow, INPUT);
myservo.attach(45); // Servo motor connected to digital pin 11
lcd.begin(16,2);
lcd.backlight();
lcd.print("Yesi Nurul Mutia");
delay(2000);
lcd.clear();
}
void loop() {
// Read PIR sensor
int pirValue = digitalRead(pirYellow);
if (pirValue == HIGH) {
digitalWrite(ledYellow, HIGH); // Turn on LED
lcd.setCursor(0, 1);
lcd.print("Gerakan Terdeteksi");
lcd.print("Yesi Nurul Mutia");
delay(1000);
digitalWrite(ledYellow, LOW); // Turn off LED
lcd.clear();
}
// Check for keypress
char key = keypad.getKey();
if (key) {
lcd.clear();
lcd.print("Key Pressed: ");
lcd.setCursor(0, 1);
lcd.print(key);
delay(1000);
lcd.clear();
}
// Read potentiometer
int potValue = analogRead(A2);
int angle = map(potValue, 0, 1023, 0, 180);
myservo.write(angle);
delay(15);
// Additional code for other tasks can be added here
}