So I am currently using a Servo motor with feedback analog feedback loop from pot to Arduino. I wanted to calibrate the values from pot to the angles 0 to 130 degrees.
I do not know if this is the most efficient way to do this. But as a beginner I have came up with code below;
MY PROBLEM: I want to catch the values of feedbackmin and feedbackmax from calibration and record them in the loop I have written with (map) function.
CODE:
// Include Arduino Servo Library
#include <Servo.h>
// Control and feedback pins
int servoPin = 9;
float feedbackPin = A0;
// Value from feedback signal
float feedbackValue;
// Calibration
float feedbackMin = ; // minimum feedback value
float feedbackMax = ; // maximum feedback value
// Create a servo object
Servo myservo;
void setup()
{
// Setup Serial Monitor
Serial.begin(9600);
// Attach myservo object to control pin
myservo.attach(servoPin);
// Home the servo motor
myservo.write(0);
// Step through servo positions
// Increment by 5 degrees
for (float servoPos = 0; servoPos <= 130; servoPos = servoPos + 1) {
// Position servo motor
myservo.write(servoPos * 1.1);
// Allow time to get there
delay(200);
// Read value from feedback signal
feedbackValue = analogRead(feedbackPin);
// Write value to serial monitor
Serial.print("Position = ");
Serial.print(servoPos);
Serial.print("\t");
Serial.println(feedbackValue);
}
// Print to serial monitor when done
Serial.println("Finished!");
float deg = 90 * 1.1;
myservo.write(deg);
delay(1000);
}
void loop()
{
Serial.println(map(analogRead(feedbackPin), feedbackMin, feedbackMax, 0, 130));
delay(500);
}
10-2_servo_cal22.ino (1.35 KB)