hello
i was hoping to pick someone's brain for a bit of advice. I am working on a project which requires some fairly precise control of a servo motor using a potentiometer. I have recently ordered the following motor from cool components - http://www.coolcomponents.co.uk/catalog/product_info.php?products_id=368 which works great and have just a simple 10k potentiometer. I have been following these instructions online as to how to connect them and the suggested code:
http://luckylarry.co.uk/2009/06/controlling-a-servo-with-arduino/
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
which have been really useful and I instantly got results. the problem i have encountered is that the motor continues to rotate, so when i turn the potentiometer it seems to controls the speed of the rotation rather than set the position of the motor (which is what I am after). The higher i turn the potentiometer the faster it turns etc. I ran a simple little programme to get a read out to the serial monitor of what data the potentiometer was sending out like this:
int potPin = 0; // select the input pin for the potentiometer
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
Serial.print(val,DEC);
Serial.print(" ");
delay(100);
}
and it seems to constantly send information as to its position -
eg. 666 666 666 666 666 646 610 571 526 480 435 390 343 294 252 211 175 142 111 79 45 15 0 0 0 0 0 0
which i guess is the problem for the servo motor as it is constantly receiving this information and moves to it. Does anyone have much experience with potentiometers and servo motors - and am I missing something?