#include <ESP32Servo.h>
// Pin definitions
const int relayPin = 12; // Connect the relay module to digital pin 2
const int ledPin = 14; // Built-in LED on most Arduino boards
const int servoPin = 27; // Connect the servo signal wire to digital pin 9
Servo myServo; // Create a Servo object to control the servo motor
void setup() {
// Initialize the relay, LED, and servo pins
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
myServo.attach(servoPin);
// Set the initial state to OFF
digitalWrite(relayPin, LOW);
digitalWrite(ledPin, LOW);
}
void loop() {
// Turn the relay and LED ON for 2 seconds
digitalWrite(relayPin, HIGH);
digitalWrite(ledPin, HIGH);
// Rotate the servo motor to 90 degrees
myServo.write(90);
delay(1000);
// Rotate the servo motor to 0 degrees
myServo.write(0);
delay(1000);
// Turn the relay and LED OFF for 2 seconds
digitalWrite(relayPin, LOW);
digitalWrite(ledPin, LOW);
// Rotate the servo motor to 90 degrees
myServo.write(90);
delay(1000);
// Rotate the servo motor to 0 degrees
myServo.write(0);
delay(1000);
}