#include <Servo.h> // include servo library
int buzzerPin1 = 5; // Define the buzzer pin
int buzzerPin2 = 6; // Define the buzzer pin
int buzzerPin3 = 7; // Define the buzzer pin
int sensorPin1 = 2; // set sensor input pin
int servoPin1 = 9; // set servo output pin
int sensorValue1; // variable to store sensor value
int sensorPin2 = 3;
int servoPin2 = 10;
int sensorValue2;
int sensorPin3 = 4;
int servoPin3 = 11;
int sensorValue3;
Servo myServo1; // create servo object
Servo myServo2; // create servo object
Servo myServo3; // create servo object
void setup() {
myServo1.attach(servoPin1); // attach servo to pin 9
myServo2.attach(servoPin2); // attach servo to pin 9
myServo3.attach(servoPin3);
Serial.begin(9600); // start serial communication
}
void loop() {
sensorValue1 = analogRead(sensorPin1); // read sensor value
Serial.println(sensorValue1); // print sensor value to serial monitor
if(sensorValue1 > 0) { // if sensor value is greater than 500
myServo1.write(180); // move servo to 90 degrees
delay(1000); // wait for 1 second
} else { // if sensor value is less than or equal to 500
myServo1.write(0); // move servo to 0 degrees
delay(1000); // wait for 1 second
}
if(sensorValue1 > 0) { // If the value is higher than 0, the IR signal is detected
digitalWrite(buzzerPin1, HIGH); // Turn on the buzzer
} else {
digitalWrite(buzzerPin1, LOW);
}
sensorValue2 = analogRead(sensorPin2); // read sensor value
Serial.println(sensorValue2); // print sensor value to serial monitor
if(sensorValue2 > 0) { // if sensor value is greater than 500
myServo2.write(180); // move servo to 90 degrees
delay(1000); // wait for 1 second
} else { // if sensor value is less than or equal to 500
myServo2.write(0); // move servo to 0 degrees
delay(1000); // wait for 1 second
}
if(sensorValue2 > 0) { // If the value is higher than 0, the IR signal is detected
digitalWrite(buzzerPin2, HIGH); // Turn on the buzzer
} else {
digitalWrite(buzzerPin2, LOW); // Turn off the buzzer
}
sensorValue3 = analogRead(sensorPin3); // read sensor value
Serial.println(sensorValue3); // print sensor value to serial monitor
if(sensorValue3 > 0) { // if sensor value is greater than 500
myServo3.write(180); // move servo to 90 degrees
delay(1000); // wait for 1 second
} else { // if sensor value is less than or equal to 500
myServo3.write(0); // move servo to 0 degrees
delay(1000); // wait for 1 second
}
if(sensorValue3 > 0) { // If the value is higher than 0, the IR signal is detected
digitalWrite(buzzerPin3, HIGH); // Turn on the buzzer
} else {
digitalWrite(buzzerPin3, LOW); // Turn off the buzzer
}
}