//#include <Arduino.h>
// code to control servo motor sg090 with esp32
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define SERVO_PIN 13
void setup() {
Serial.begin(115200);
myservo.attach(SERVO_PIN); // attaches the servo on pin 13 to the servo object
}
void loop() {
// sweep the servo fro 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
// sweep the servo from 180 to 0 degrees
for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}