Go Down

Topic: Potentiometer on a Servo (Read 634 times) previous topic - next topic

E_ri_k

Hi, everyone i'm new here. I have been working with Arduino for a few months now. I have some basic electronics knowlege.
I am trying to control a servo motor with a potentiometer, which I have managed to do, however sometimes the servo will go out of control, back and forth. I managed to isolate the problem down to the potemtiometer and the wires connecting to it. If I twist the wires to a certain position there is no erratic behaviour, also if I squeeze the pot or the 3 wires leading to it really hard it works fine. I have placed a cable tie tightly around the wires on the pot contacts, and it is working quite well. It is like there is some interferance coming from somewhere. All the connections are soldered well, and I have tried different pots with the same result, so it cant be a loose contact.

I dont understand what is going on???

robtillaart

Welcome,

Please post your code and a schematic if possible,
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

E_ri_k

Here is the code:
Code: [Select]
#include <Servo.h>

Servo myservo; 

int potpin = 0;
int val;   

void setup()
{
  myservo.attach(9);
Serial.begin(9600);
}

void loop()
{
  val = analogRead(potpin);           
  val = map(val, 0, 1023, 0, 179);     
  myservo.write(val);                 
  delay(15);                           
  Serial.println(val);
} [code]
Everything is soldered and heat shrinked.
[/code]

AWOL

Is the wire solid or stranded?
How long is the wire?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

robtillaart

Code looks good. You might do multiple readings from the pot and average them to remove some noise of the ADC

Code: [Select]

void loop()
{
  val = 0;
  for (int i=0; i< 4; i++) val += analogRead(potpin);
  val = val/4;         
  val = map(val, 0, 1023, 0, 179);
 
  myservo.write(val);
         
  delay(15);                           
  Serial.println(val);
}


Some questions:
How about the wires to the servo?
TYpe of Servo? 
datasheet?
how much milli amps does it draw?
What powersupply are you using?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up