servos and potentiometers

hello guys i am struggling to write sketches im a complete newbie to electronics but am very keen i was planning on making a robotic arm which uses 5 servos and are cntrolled by 5 pots but i cannot configure a sketch/code that works at all with the uno, if anyone could have on ei could use or give some advice it would be greatly appreciated,

atb

Check the IDE servo knob example code.

thanks for the reply i have managed to get that code to work with 1 pot and 1 servo but how do i change it to control 5?

You'll need to define and attach() five Servo objects, on different pins.
You'll need to define five potpin variables, on different analogue pins.
You'll then need to replicate the parts that read the potpin and writes the Servo position.

do you have an example you could show me?

thanks

You have the example. It shows you how to create and use a single servo object. Study it. Look at the reference material on this site. Try adding one more servo to the existing sketch.

Make sure that you don't try powering the servos from the Arduino - Use an external power source.

this is what i have come up with im not sure of the layout

#include <Servo.h>

Servo myservo;

int potpin = 0;
int val;

int potpin = 1;
int val;

void setup()
{
myservo.attach(9);
myservo.attach(3);
}

void loop()
{
val = analogRead(potpin)0;
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);

val = analogRead(potpin)1;
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
}

Servo myservo;

What part of "Create TWO servo objects" didn't you understand?

  myservo.attach(9);
  myservo.attach(3);

Which pin is the servo really attached to?

int potpin = 0;
int val;

int potpin = 1; 
int val;

You didn't even bother trying to compile this, did you?

when i compile it says 'servo' was not declared in this scope.
im not sure what this means

#include <Servo.h>

Servo myservo1;
Servo myservo2;

int potpin1 = 0;
int potpin2 = 1;

int val_0;
int val_1;

void setup()
{
servo.attach(9);
servo.attach(3);
}

void loop()
{
val = analogRead(potpin)0;
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);

val = analogRead(potpin)1;
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
}

yet again sorry for my stupidity

atb

when i compile it says 'servo' was not declared in this scope.
im not sure what this means

It means that you just made up a new name. You create two instances of the Servo class, myservo1 and myservo2. Then, you try to attach servo to two different pins. That is what the compiler is complaining about.

It should be obvious that you need to attach myServo1 to one pin and myServo2 to the other pin.

  val = analogRead(potpin)0;

What is that 0 there for? potpin is not defined, either. Nor is val.

  myservo.write(val);

Nor is myservo.

  val = analogRead(potpin)1;

And the 1?

servo 1 is connected to pin 9 and servo 2 is connected to pin 3

#include <Servo.h>

Servo servo1;
Servo servo2;

int potpin1 = 0;
int potpin2 = 1;

int val_0;
int val_1;

void setup()
{
servo1.attach(9);
servo2.attach(3);
}

void loop()
{
val_0 = analogRead(potpin1);
val_0 = map(val, 0, 1023, 0, 180);
servo1.write(val);
delay(15);

val_1 = analogRead(potpin2);
val_1 = map(val, 0, 1023, 0, 180);
servo2.write(val);
delay(15);
}

is this what you mean?

is this what you mean?

Does it compile? Does it do what you want? If so, then, yes, that is what we meant.

It certainly looks, at a cursory glance, a lot better, except that you still reference val.

it still wont compile, now it says val was not declared in this scope

void loop()
{
val_0 = analogRead(potpin1);

val_0 = map(val, 0, 1023, 0, 180); < this peice becomes highlighted
servo1.write(val);
delay(15);

val_1 = analogRead(potpin2);
val_1 = map(val, 0, 1023, 0, 180);
servo2.write(val);
delay(15);
}

Hint:

val_1 = analogRead(potpin2);
val_1 = map(val, 0, 1023, 0, 180);
servo2.write(val);
delay(15);

thank you very much indeed it finally works! XD :fearful: