#include <Servo.h> // Include the Servo library
const int potPin = A0; // Potentiometer connected to analog pin A0
Servo myServo; // Create a Servo object
void setup() {
Serial.begin(9600); // Start the serial communication at 9600 baud
myServo.attach(9); // Attach the servo on pin 9
}
void loop() {
int potValue = analogRead(potPin); // Read the potentiometer value
// Print the raw potentiometer value for debugging
Serial.print("Raw Potentiometer Value: ");
Serial.println(potValue);
int potValue_Mapped = map(potValue, 0, 1023, 0, 180); // Map the value to an angle (0-180 degrees)
// Print the mapped potentiometer value for debugging
Serial.print("Mapped Potentiometer Value: ");
Serial.println(potValue_Mapped);
myServo.write(potValue_Mapped); // Set the servo position
delay(100); // Wait for 100 milliseconds
}