Pages: [1]   Go Down
Author Topic: Potentiometer on a Servo  (Read 616 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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???
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 228
Posts: 14059
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Welcome,

Please post your code and a schematic if possible,
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the code:
Code:
#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]


* DSC00278.jpg (155 KB, 480x270 - viewed 13 times.)

* DSC00277.jpg (148.02 KB, 480x270 - viewed 14 times.)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26637
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is the wire solid or stranded?
How long is the wire?
Logged

"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.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 228
Posts: 14059
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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?
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is stranded copper wire. CAT5 Ethernet cable. It is about 500mm long. It plugs into a socket soldered onto a arduino prototype board, which then leads to digital pin 9 and analog pin 0. The setup works fine, with the cable ties as in the picture, but it becomes erratic if they are removed.

The servo is a HITEC HS-300. Im not sure how much current it draws. It is out of an old model aeroplane I had. Im using a 9 volt 800mA power supply. Either with the 9V or the USB cable I get the same problem.
« Last Edit: July 18, 2011, 07:10:56 am by E_ri_k » Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


   Possible causes: bad solder joints, insulation cut to cause shorts between wires, broken wires.


Mark
Logged


Pages: [1]   Go Up
Jump to: