//Name: Rohit Kumar, Reg. No: 12110865, Roll No: 10
#include <ESP32Servo.h>
// Pin Definitions
#define POTENTIOMETER_PIN 34 //15 also work, Pin where potentiometer is connected (Analog pin)
#define SERVO_PIN 18 // Pin where servo motor is connected
Servo myServo; // Create servo object
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
// Attach the servo on the specified pin
myServo.attach(SERVO_PIN);
// Set initial position for the servo (90 degrees)
myServo.write(90);
}
void loop() {
// Read the potentiometer value (analog value between 0 and 4095)
int potValue = analogRead(POTENTIOMETER_PIN);
// Map the potentiometer value to a servo angle (0 to 180 degrees)
int servoAngle = map(potValue, 0, 4095, 0, 180);
// Write the angle to the servo
myServo.write(servoAngle);
// Print the values for debugging
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print(" | Servo Angle: ");
Serial.println(servoAngle);
// Small delay to stabilize the servo motor movement
delay(15);
}