#include <Servo.h>
#include <IRremote.hpp>
const int irReceivePin = 5, buzzerPin = 10, servoPin = 4;
const unsigned long powerCode = 162;
Servo doorServo;
int currentAngle = 0;
void toggleDoor()
{
if (currentAngle == 0)
{
doorServo.write(90);
currentAngle = 90;
buzz(10);
Serial.println("Door Status : OPEN!");
} else {
doorServo.write(0);
currentAngle = 0;
buzz(20);
Serial.println("Door Status : CLOSED!");
}
}
void buzz(int duration)
{
for(int i = 0; i<duration; i++)
{
digitalWrite(buzzerPin, HIGH);
delay(9);
digitalWrite(buzzerPin, LOW);
delay(1);
}
}
void setup()
{
doorServo.attach(servoPin);
doorServo.write(currentAngle);
Serial.begin(9600);
IrReceiver.begin(irReceivePin, ENABLE_LED_FEEDBACK);
pinMode(buzzerPin, OUTPUT);
Serial.println("Door Control System Initialized!");
}
void loop()
{
if (IrReceiver.decode())
{
if (IrReceiver.decodedIRData.command == powerCode)
toggleDoor();
IrReceiver.resume();
Serial.print("Current Servo Angle: ");
Serial.println(currentAngle);
Serial.println();
}
}