#include #include #define BUZZER_PIN 9 Servo servo1; Servo servo2; void setup() { pinMode(BUZZER_PIN, OUTPUT); servo1.attach(5); // Servo motor 1 servo2.attach(6); // Servo motor 2 Wire.begin(0x02); // Initialize as slave with address 0x02 Wire.onReceive(receiveEvent); } void loop() { // Nothing in loop; everything is handled in receiveEvent } void receiveEvent(int bytes) { int distance = Wire.read(); // Read distance from master if (distance < 20) { digitalWrite(BUZZER_PIN, HIGH); // Trigger buzzer } else { digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer } int servoAngle = map(distance, 0, 100, 0, 180); // Map distance to servo angle servo1.write(servoAngle); servo2.write(180 - servoAngle); // Opposite angle for second servo }