#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define the LCD display connections
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define the servo motor
Servo myservo;
int servoPin = 10;
// Define the pin connections
int ledPin = 13;
int motionSensorPin = 2;
void setup() {
// Initialize the servo motor
myservo.attach(servoPin);
// Initialize the LCD
lcd.init();
lcd.backlight();
// Initialize the LED and motion sensor
pinMode(ledPin, OUTPUT);
pinMode(motionSensorPin, INPUT);
}
void loop() {
// Check if motion is detected
if (digitalRead(motionSensorPin) == HIGH) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
// Display message on LCD
lcd.setCursor(0, 0);
lcd.print("Feeding pet...");
// Open the pet feeder
myservo.write(90);
// Wait for 5 seconds
delay(5000);
// Close the pet feeder
myservo.write(0);
// Clear the LCD
lcd.clear();
// Turn off the LED
digitalWrite(ledPin, LOW);
}
}