#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Servo motor1;
Servo motor2; // Membuat objek servo bernama myservo
int LDR = A0;
int PIR = 2;
LiquidCrystal_I2C LCD(0x27, 16, 2);
void setup() {
//Serial.begin(9600);
LCD.init();
pinMode(PIR, INPUT);
motor1.attach(11);
motor2.attach(10); // Mengatur pin digital 9 untuk mengontrol servo
}
void loop() {
//int nilaiLDR = analogRead(LDR);
//Serial.println(nilaiLDR);
int nilaiPIR = digitalRead(PIR);
if (nilaiPIR == HIGH) {
LCD.backlight();
LCD.setCursor(0, 0);
LCD.println("Sensor Detacted");
LCD.setCursor(0, 1);
LCD.println("");
delay(3000);
LCD.clear();
LCD.setCursor(3, 0);
LCD.println("Formation 2");
LCD.setCursor(5, 1);
LCD.println("Move");
delay(3000);
motor1.write(180);
motor2.write(90);
delay(2500);
LCD.clear();
motor1.write(0);
motor2.write(0);
} else {
LCD.backlight();
LCD.setCursor(0, 0);
LCD.println("INFORMATIKA");
LCD.setCursor(0, 1);
LCD.println("SIMULATION 2");
delay(3000);
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("SensorUndetacted");
LCD.setCursor(0, 1);
LCD.println("");
delay(3000);
LCD.clear();
LCD.setCursor(3, 0);
LCD.println("Formation 1");
LCD.setCursor(5, 1);
LCD.println("Move");
delay(3000);
motor1.write(90);
motor2.write(180);
delay(2500);
LCD.clear();
motor1.write(0);
motor2.write(0);
}
//delay(100);
}