#include <Servo.h>
int servoPin = 11;
Servo servo1;
#define stepsVal 10
uint8_t stepsCounter = 180 / stepsVal;
//This Code will move the servo smoothly from 0 to 180 degrees in steps
// and then return it back to the starting position
void setup() {
// setup code here, to run once:
servo1.attach(servoPin);
}
void loop() {
for (int i = 0; i <= stepsCounter; i++) {
int position = i * stepsVal; // Move the servo in increments
servo1.write(position); // Move servo to the calculated position
delay(1000); // Wait for 1 second
}
//Return servo to start position smoothly
for (int i = stepsCounter; i >= 0; i--) {
int position = i * stepsVal;
servo1.write(position);
delay(1000);
}
}