Hi,
My goal is to control the servo through the use of the petentiometer, where depending on how far I turn the petentiometer, which is the resistance, it correlates to the amount of degrees the servo turns to.
In order to achieve this, I combined the Basics Analog Read Serial circuit (which is here on this website under Learning --> Tutorials --> Built in Examples) with the USK guide Code (from viros.com). The same can be said for my code, with slight modifications here and there. However, the servo is not responding in the desired way, and i don't understand why
Here is my code:
#include <Servo.h> // servo library
Servo servo1; // servo control object
void setup()
{
Serial.begin(9600); //initialized communication speed
servo1.attach(9); //correlates control of servo to pin 9
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue); //printing of sensorValue 's (its excessive to servo control, but has uses)
delay(1);
servo1.write(sensorValue * 180 / 1023); // conversion factor from resistance value to degrees modifies sensorValue into degrees, and then is outputed as the value of degrees for servo to go to
delay(20);
}
What happens is the servo does move slightly when I twist the petentiometer, but it doesn't move in correlation to how much I turn it, and it seems unpredictable in its turning. Also, its constantly buzzing, even when I don't touch the petentiometer. What am I doing wrong?
Thanks,
Davidka
PS
If you have any questions, or suspicions, please comment. Even if you don't think your right, or even if you don't know why but have a direction to turn to, please respond. It might ring a bell for me, or a start a conversation between us that might lead us to a resolution.