#include <Servo.h>

Servo myservo1;  // Create servo object to control the first servo
Servo myservo2;  // Create servo object to control the second servo
int irSensor = 2;  // IR sensor connected to digital pin 2
int servoPin1 = 9;  // First servo connected to digital pin 9
int servoPin2 = 10; // Second servo connected to digital pin 10
int sensorValue;
bool isTriggered = false;  // Flag to check if the trap has been triggered

void setup() {
  myservo1.attach(servoPin1);  // Attach the first servo on pin 9
  myservo2.attach(servoPin2);  // Attach the second servo on pin 10
  pinMode(irSensor, INPUT);  // Set IR sensor as input
  myservo1.write(0);  // Initial position of the first servo (door open)
  myservo2.write(0);  // Initial position of the second servo (door open)
  Serial.begin(9600);
}

void loop() {
  sensorValue = digitalRead(irSensor);  // Read the IR sensor
  Serial.println(sensorValue);
  
  if (sensorValue == LOW && !isTriggered) {  // If the sensor is disturbed and the trap hasn't been triggered yet
    myservo1.write(180);  // Rotate first servo to 180 degrees (door closes)
    myservo2.write(180);  // Rotate second servo to 180 degrees (door closes)
    isTriggered = true;  // Set flag to indicate the trap has been triggered
  }
}
