#include <Servo.h>
Servo gateServo; // Create a servo object
int irSensorPin = 2; // IR sensor pin
int openAngle = 0; // Opening angle of the gate
int closeAngle = 180; // Closing angle of the gate
void setup() {
gateServo.attach(9); // Attaches the servo on pin 9 to the servo object
pinMode(irSensorPin, INPUT); // Set IR sensor pin as input
}
void loop() {
int sensorValue = digitalRead(irSensorPin); // Read IR sensor value
if (sensorValue == HIGH) {
gateServo.write(openAngle); // Open the gate to 0 degree
} else {
gateServo.write(closeAngle); // Close the gate to 120 degree
}
}