const int potPin = A0; // Potentiometer connected to analog pin A0
const int servoPin = 9; // Servo connected to digital pin 9
void setup() {
// Set servo pin as output
pinMode(servoPin, OUTPUT);
}
void loop() {
// Read the potentiometer value (0 to 1023)
int potValue = analogRead(potPin);
// Manually calculate the pulse width (1000 to 2000 microseconds) based on potValue
int pulseWidth = potValue * (1000.0 / 1023.0) + 1000;
// Generate the PWM signal manually
digitalWrite(servoPin, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoPin, LOW);
// Wait for the remainder of the 20ms period (standard for servos)
delay(20 - pulseWidth / 1000);
}