Pages: [1]   Go Down
Author Topic: 3 Servos using 3 Potentiometers to Arduino Uno  (Read 2343 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have 3 servos connected to an arduino uno. I am controlling these using potentiometers. Looking at the program below I used the "pin" value as the wire from the potentiometer to the corresponding analog pin on the arduino. Plugging the servos yellow wire to the corresponding wire it is attached to on the digital side of the arduino. After controlling the servos they seem to sometimes respond and then go off rotating in their own pattern. When the potentiometer is responding and I get it to a position I need it to hold, it seems to make a clicking noise, like the gears are going back and forth very quickly. My program is attached below, let me know what you guys have in mind.

#include <Servo.h>
 
Servo arm;  // serevo that holds arm in fire ready position
Servo spring; // servo for spring tensioning
Servo angle;// servo for changing degree of the arm and reloading
 
int armpin = 0;  // analog pin used to connect the potentiometer for arm
int armval;    // variable to read the value from the analog pin for arm
int springpin = 2; //analog pin used to connect the potentiometer for spring
int springval;    // variable to read the value from the analog pin for spring
int anglepin = 4; // analog pin used to connect the potentiometer for angle
int angleval;  // variable to read the value from the analog pin for angle

void setup()
{
  arm.attach(9);  // attaches the servo on pin 9 to the servo object
  spring.attach(11); // attaches the servo on pin 11 to the servo object
  angle.attach(6); // attaches the servo on pin 6 to the servo object
}
 
void loop()
{
  armval = analogRead(armpin);            // reads the value of the potentiometer (value between 0 and 1023)
  armval = map(armval, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  arm.write(armval);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
  springval = analogRead(springpin);            // reads the value of the potentiometer (value between 0 and 1023)
  springval = map(springval, 2, 1023, 2, 179);     // scale it to use it with the servo (value between 0 and 180)
  spring.write(springval);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
  angleval = analogRead(anglepin);            // reads the value of the potentiometer (value between 0 and 1023)
  angleval = map(angleval, 4, 1023, 4, 179);     // scale it to use it with the servo (value between 0 and 180)
  angle.write(angleval);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The first question we ask for problems like this is how are you powering your three servos. If they are all getting power from the arduino's 5v pin then that is probably the root of all (or at least some of) your troubles. Arduinos are great at controlling servos and other stuff but really suck at powering things. Servos have motors in them, motors draw lots of current, and 3 servos is just insane to try and power from the shield 5v pin. So you should look for another source of regulated +5vdc voltage to wire power the servos, plan on 1 amp of current capacity for each servo, so you should be looking for a 3amp supply. Four AA alkiline cells will work also but may have limited duration before exhaustion. Also whatever your new source of external power is be sure to add a ground wire from it's negative terminal to an arduino ground pin.

Good luck;

Lefty
Logged

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

I just tried a 5v 2 amp power supply. The servos were very jittery going back and forth very fast almost looked like everything attached was shaking. The potentiometers are also powered using the supply. Any suggestions?
Really appreciated Thanks!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are the resistance values of the pots you are using. Too high a value can give you 'jumpy' numbers. 10K ohms or less are best to use. Also servos usually can't process new values much faster then 25 millisec so you might want to increase your delay() values a little.

Lefty
Logged

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

Ok so my pots were rated for 25ohm so Im gonna try some 10 ohm. And what would you suggest changing the delay values to? I am very new to the arduino.
Thanks
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so my pots were rated for 25ohm so Im gonna try some 10 ohm. And what would you suggest changing the delay values to? I am very new to the arduino.
Thanks

No, no those are drawing too much current as it is. I said 10,000 ohms or less meaning down to maybe 1K. A ten ohm pot across +5vdc and ground will draw 500 ma of current by itself for no useful purpose other then to help heat up your room! Get some properly sized pots with enough zeros after the one.  smiley-wink

Lefty
« Last Edit: December 04, 2012, 09:45:52 pm by retrolefty » Logged

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

ok the old ones were 25k but i have some 10k pots I can try. Any suggestion on the delay value? I am using each servo to move about 90 degrees. they are lifting pieces of wood attached to a catapult so I need the most power I can get out of these.
Thanks again
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would start with say delay(100) and see how it operates. If it seems to sluggish decrease the value by 10 each try until you find a sweet spot for your specific servos. A lot depends on how far you are asking the position to change with each cycle of your main loop and of course the individual speed of your servos which can vary a lot between servo models. You can gain a little more speed and power if you can increase the servo voltage up to 6vdc, but don't go any higher then that in voltage.

Lefty
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest you go back and start eith the "knob" example code and get one servo working correctly first. Below is a typical servo wiring setup. "The potentiometers are also powered using the supply. Any suggestions?". you need to power the pot from the arduino 5v pin.

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

I have run this code using 1k potentiometers with no problem while powered by the USB cable, hooked to my computer. I have 3micro servo's also connected. Everything responds just fine. My problem is this, when I power the board with a walwart/5v/2.4a, the servos just take off spinning with no response to the pots. Hook back up the USB and it's all good. What the heck is going on? Anybody?.....
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you power the arduino from an external power source (via external jack?), what is the voltage on the arduino 5v pin?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

Ah yes. It was the walwart.  I hadn't realized that the Arduino would drop that much voltage. After reading more, I saw where it is recommended to use 9~18Vdc. Tried a 7v (it was my only other choice) and things worked great.
Logged

Pages: [1]   Go Up
Jump to: