int potPin = A0; // analog input pin for the potentiometer
int angleMin = 0; // minimum angle (in degrees)
int angleMax = 30; // maximum angle (in degrees)
int vMin = 512; // voltage output of the potentiometer at minimum angle
int vMax = 600; // voltage output of the potentiometer at maximum angle
void setup() {
Serial.begin(9600); // initialize serial communication
pinMode(potPin, OUTPUT);
}
void loop() {
// read the voltage output of the potentiometer
int vPot = analogRead(potPin);
// calculate the corresponding angle using the calibration formula
float angle = (vPot - vMin) * (angleMax - angleMin) / (vMax - vMin) + angleMin;
// print the angle to the serial monitor
Serial.print("Angle: ");
Serial.print(angle);
Serial.print(" degrees");
Serial.print(" Voltage ");
Serial.println(vPot);
delay(100); // wait for a short time before reading the potentiometer again
}
// IMPORTANT MAX ANGLE = 25-45 EACH WAY