arduino+many servos+potentiometers

hello everybody...i am newbie here so i want your help for a project...sorry that my english is not so good...i want to make a robot arm where servos are controlled by potentiometers....exactly when i wire up 2 or more servos it doesnt work any of the servos...i used the classic servo knob exaple but when i wire up even the second servo doesnt move anything!! i will use 6 servos where the 2 of them i want the 2 servos to be manipulated by the same potentiometer and the rest of them to be manipulated by each potentiometers!!can you please help me cause i looked for but i did not find something usefull.....thanx ...

It sounds like you are trying to power the servos from the Arduino. The Arduino can't provide enough current to drive multiple servers, or even one depending on the servo's power requirement. You will need a separate power supply for the servos. Don't forget to connect the grounds together.

Post your code so we can look at them for mistakes.

#include <Servo.h>

Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo

int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 2; // analog pin used to connect the potentiometer
int val1; // variable to read the value from the analog pin
int val2; // variable to read the value from the analog pin

void setup() {
myservo1.attach(9); // attaches the servo on digital pin 9 to the servo object
myservo2.attach(10); // attaches the servo on digital pin 10 to the servo object
}

void loop()
{
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val1); // sets the servo position according to the scaled value

val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val2); // sets the servo position according to the scaled value

delay(15); // waits for the servo to get there
}

now works perfectly!!! but i ll need to use 6 servos!! i think that i ll need new library..but i cant find it..can you help me??? and how has to be the code after the entry of that library??

delay(15); // waits for the servo to get there

They are quick servos if they get to position that fast.

but i ll need to use 6 servos!

I have used that library for 8 servos.

johnkastoria:
now works perfectly!!! but i ll need to use 6 servos!! i think that i ll need new library..but i cant find it..can you help me??? and how has to be the code after the entry of that library??

Good for you but it doesn't help anyone reading this thread if you didn't say what you did to make it work. Do everyone a favor an share what you changed. You'll be thanked.

but i ll need to use 6 servos!!

Unless you really like typing and debugging, now is the time to learn about arrays and for loops.

Unless you really like typing

Problem nowadays is that copy and paste is so easy it reduces the incentive to learn how to program properly with loops.
When you had to punch your own cards, flip switches to toggle in a program, or even type it all into a keyboard, that was the incentive to make the code have as few lines as possible.

Problem nowadays is that copy and paste is so easy it reduces the incentive to learn how to program properly with loops.

Until you forget, in the fourteenth iteration, to change the name of the variable, and spend the rest of the night wondering about the growing pile of hair in front of you ]:smiley:

This is how they learn programming nowadays, starting from copy paste and patch. If the OP has motive to learn more about programming, he will learn more about programming in more elegant ways most people learn from classes. If I didn't know programming and you told me to use arrays for stuff, I'd ask why? I was using discrete variables just fine. This is not a class where he has to demonstrate some skills with arrays to pass :slight_smile:

I'd ask why?

So that s/he doesn't come back here in three days time with a simple typo bug.

AWOL:

I'd ask why?

So that s/he doesn't come back here in three days time with a simple typo bug.

Assuming I still don't know programming, I'd have a hard time going from what works right now to what should work but needs code rewrite. I'd be unwilling to change but just keep doing what I know works to get more servos to move. It's a force of habit. Every day I step in my lecture hall, I can predict with utmost accuracy where each of my students is going to sit. I have no hope to change study habits of them but hope to change their interests in the topics I teach.

But that is why you have to try. I had a hard time trying to persuade my students to use HEX, I said it would make things a lot easier. Some would not put in the small amount of work and kept on doing it the long way converting bit patterns back and forth. In other words they replaced ability with effort.

You can go a long way applying more and more effort but eventually it all falls in a heap. Unfortunately with an ever increasing percentage of students being taken on that happens more and more and so devalues the qualifications. We get it every year, it suites governments to reward effort and not ability because those are the sort of people who are easily manipulated. It has happened to the primary and secondary school population of teachers with the National Curriculum in the UK.

Most kids don't like schools and aren't motivated to lift a finger to explore anything. They don't go to school because they want to learn or they meet difficulty and want answers. They are schooling but not learning. I think OP is motivated to learn, which is why the post. So let him see the ugly mess of not using arrays and he'll be very willing to listen, just my $0.02.

Most kids don't like schools and aren't motivated to lift a finger to explore anything.

Sadly that is true, there fate in life is to be bored. Then the big corporations can sell them things to attempt to entertain them but ultimately they will be bored, it's quite sad.

well, i wired up the potentiometers and the servos as it is said in the servo knob examples..i guess i only need now the library to manipulate many servos..but wich library is that?thanks for the replies guys..
ps: i dont have problem to study and learn new things but i am newbie and thats the reason i asked for your help..

i guess i only need now the library to manipulate many servos.

The Servo library.
The one described in the examples.
The one you were using in post #3.

You just need to do attach to each servo and make sure the digital pin is a PWM pin. That limits it to a maximal of 6 servos.

The above was wrong :blush:

make sure the digital pin is a PWM pin

?