#include <Servo.h>
#include <IRremote.h>//Include the IRremote library
#define OPEN_CODE 24
#define CLOSE_CODE 48
int servoPin=10;
int irPin=11;
Servo gateServo;
IRrecv status(irPin);
decode_results results;
void setup() {
// put your setup code here, to run once:
gateServo.attach(servoPin);
status.enableIRIn(); // Start the IR receiver
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (status.decode())
{
switch (status.decodedIRData.command)
{
case OPEN_CODE:
openGate();
break;
case CLOSE_CODE:
closeGate();
break;
// Add more cases for other actions if needed
}
status.resume(); // Receive the next IR code
}
}
void openGate()
{
gateServo.write(90); // Set the servo to open position (adjust angle as needed)
delay(1000); // Delay to allow the gate to open (adjust as needed)
}
void closeGate()
{
gateServo.write(0); // Set the servo to close position (adjust angle as needed)
delay(1000); // Delay to allow the gate to close (adjust as needed)
}