#include <ESP32Servo.h>
// Define pins
#define SERVO_PIN 15
#define BUZZER_PIN 13
// Create a Servo object
Servo myservo;
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Attach the servo to the pin
myservo.attach(SERVO_PIN);
// Set buzzer pin as output
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
// Turn on the servo to a specific angle and the buzzer simultaneously
Serial.println("Servo and Buzzer ON");
myservo.write(90); // Rotate servo to 90 degrees
tone(BUZZER_PIN, 1000); // Start buzzer with 1000 Hz frequency
delay(1000); // Wait for 1 second
// Turn off the servo and the buzzer
Serial.println("Servo and Buzzer OFF");
myservo.write(0); // Rotate servo back to 0 degrees
noTone(BUZZER_PIN); // Stop the buzzer
delay(1000); // Wait for 1 second before the next cycle
}