Servo control with joystick modules or potentiometers

Helloo everyone, My first post, Iv been playing around with arduino for a while now, Trying all diffrent example projects.
I love this stuff, Im hooked now.

Can some one steer me in the right direction, I dont want to be spoon fed, I want to learn.

So im trying to control 6 high torque metal geard servos for robotic arm control, But most information is for control with potentiometers ,And then information that is out there for joysticks is confusing as hell.

So need to control 4 servos with 2 joystick modules and the 5th servo controled with a potentiometer.

A pot can swing from min to max, and produces an A/D value between 0 and 1023.
That can be easilly mapped with the map() command to 0-180 (degrees) for the servo.
Try to display that first on the serial monitor.
Don't think of adding a servo yet.

A joystick is basically two pots (for the two axes), so two analogue inputs are needed.
Bit trickier, because they usually don't have a full swing.
Get the min and max values first (as with the pot), and then map the min and max values to 0-180 degrees.
You might have to use constrain() to stop the values going over the limits you set.

The use of map() and constrain() can be found in the help>reference tab of the IDE.
Post your best attempt if you need help with that.
Leo..

If you wish th be able to use a self-centering joystick in such a way that pushing it forward moves the servo in one direction and pulling it back moves the servo in the other direction and when you let go of the joystick the servo stays where it is then the code in this link will help get you started.

...R

Thanks wawa, you just taught me something new.

Thats exactly the sort of info i need to read.
Ill post my results soon, Thanks to robin.

This is the schematic im following and the code has to be downloaded, im a little confused with the picture.

Nexhttp://fritzing.org/projects/six-servo-motors-controlled-by-six-potentiometers ,
There is a 10K with the little headphone icon in the wiring schematics.

This is were im confused.
Dose that mean use a 10k potentiometer ?
Or dose it mean there is 10k resistors included in the + wires that lead to each potentiometer ?

Fritzing diagrams are next to useless for understanding circuit connections. However those are 10k potentiometers. That is the ideal value for use with the Arduino ADC.

...R

Not sure what you mean. The only headphone thingies I see are omega symbols (Google it).
10kΩ meaning 10,000 ohms.

Your joystick could have pots with other resistance values (5k, 20k), but that's ok.
What the Arduino measures is a voltage ratio from the pot, not the actual resistance.

Pots have three terminals. The middle one going to the anlogue input.
The outside terminals go to 5volt and ground.
If the pot behaves opposite, then swap the wires to the outside terminals.

Start experimenting with ONE pot, and e.g. the ReadAnalogueVoltage sketch from File>Examples>Basics menu of the IDE.
Leo..

yes wawa, Thank you, everything you describe makes complete sense and has already taught me so much and still are.
Yes those joystick modules dont have a full swing,
But my idea was to be able to control a robotic arm the same way an excavator machine controls work, But using a 6 axis robotic arm.
I have made everything by hand exept for using a cordless drill.

Now realising joysticks dont have a full swing, Im going to start with potentiometers now just to understand it better before upgrading to something a little more advanced.

FLCFLC:
But my idea was to be able to control a robotic arm the same way an excavator machine controls work,

The code in the link I gave you is intended for that sort of control system.

...R

i have followed the wiring diagram, But the code is was still wrong.

4 of the servos are not even declared, So i changed that, But now a new problem comes up in the error message, expected before; servo1.

Hears the sketch as im upto.

// Servo motor control with potentiometer
// based on example at www.arduino.cc

#include <Servo.h>

Servo servo1; // create an object of type servo 1 to access the methods
int potpin1 = 0; // sets the analog pin 0 to turn on potentiometer 1
int val1; // variable to store the read value of the analog pin 0
Servo servo2; // create an object of type servo 2 to access the methods
int potpin2 = 1; // sets analog pin 1 to switch on potentiometer 2
int val2; // variable to store the read value of the analog pin 1
Servo servo3; // create an object of type servo 3 to access the methods
int potpin3 = 2; // sets the analog pin 2 to turn on the potentiometer 3
int val3; // variable to store the read value of analog pin 2
Servo servo4; // create an object of type servo 4 to access the methods
int potpin4 = 3; // sets the analog pin 3 to turn on the potentiometer 4
int val4; // variable to store the read value of the analogue pin 3
Servo servo5; // create an object of type servo 5 to access the methods
int potpin5 = 4; // sets the analog pin 4 to turn on the potentiometer 5
int val5; // variable to store the read value of analog pin 4
Servo servo6; // create an object of type servo 6 to access the methods
int potpin6 = 5; // sets the analog pin 5 to turn on the potentiometer 6
int val6; // variable to store the read value of analog pin 5

void setup ()
{
servo1.attach (3); // assign arduino pin 3 to be controlled by the object
servo2.attach (4); // assign arduino pin 5 to be controlled by the object
servo3.attach (5); // assign arduino pin 6 to be controlled by the object
servo4.attach (9); // assign arduino pin 9 to be controlled by the object
servo5.attach (10); // assign arduino pin 10 to be controlled by the object
servo6.attach (11); // assign arduino pin 11 to be controlled by the object
}

void loop ()
{
val1 = analogRead (potpin1); // read the value of potentiometer 1 (values ​​between 0 and 1023)
val1 = map (val1, 0, 1023, 0, 185) // scales used by the servo (values ​​between 0 and 180)
servo1.write (val1); // arrow the servo 1 according to the position (scala) read above by analogRead ()
val2 = analogRead (potpin2); // read the value of potentiometer 2 (values ​​between 0 and 1023)
// scales used by the servo (values ​​between 0 and 180)
servo2.write (val2); // arrow the servo 2 according to the position (scala) read above by analogRead ()
val3 = analogRead (potpin3); // read the value of potentiometer 3 (values ​​between 0 and 1023)
val3 = map (val3, 0, 1023, 0, 185) // scales used by the servo (values ​​between 0 and 180)
servo3.write (val3); // arrow the servo 3 according to the position (scala) read above by analogRead ()
val4 = analogRead (potpin4); // read the value of potentiometer 4 (values ​​between 0 and 1023)
val4 = map (val4, 0, 1023, 0, 185) // scales used by the servo (values ​​between 0 and 180)
servo4.write (val4); // arrow the servo 4 according to the position (scala) read above by analogRead ()
val5 = analogRead (potpin5); // read the value of potentiometer 5 (values ​​between 0 and 1023)
val5 = map (val5, 0, 1023, 0, 185) // scales used by the servo (values ​​between 0 and 180)
servo5.write (val5); // arrow the servo 5 according to the position (scala) read above by analogRead ()
val6 = analogRead (potpin6); // read the value of potentiometer 6 (values ​​between 0 and 1023)
// scales used by the servo (values ​​between 0 and 180)
servo6.write (val6); // arrow the servo 6 according to the position (scala) read above by analogRead ()
}

If you start of from scratch from the code that is downloaded from the frizzzzing place the first problem is the servos are not declared and then son and so on.

Im a little stuck is all.

Please use the code button </> when posting code.

And if you delete all the repetitive comments and add a little white space you can actually see the code - like this

// Servo motor control with potentiometer
// based on example at www.arduino.cc

#include <Servo.h>

Servo servo1;    // create an object of type servo 1 to access the methods
int potpin1 = A0; // sets the analog pin 0 to turn on potentiometer 1
int val1;        // variable to store the read value of the analog pin 0

Servo servo2;
int potpin2 = A1;
int val2; 

Servo servo3; 
int potpin3 = A2; 
int val3;

Servo servo4; 
int potpin4 = A3; 
int val4; 

Servo servo5; 
int potpin5 = A4;
int val5; 

Servo servo6; 
int potpin6 = A5; 
int val6; 

void setup ()
{
  servo1.attach (3); // assign arduino pin 3 to be controlled by the object
  servo2.attach (4); 
  servo3.attach (5); 
  servo4.attach (9); 
  servo5.attach (10); 
  servo6.attach (11); 
}

void loop ()
{
  val1 = analogRead (potpin1);        // read the value of potentiometer 1 (values between 0 and 1023)
  val1 = map (val1, 0, 1023, 0, 185); // scales used by the servo (values between 0 and 180)
  servo1.write (val1);                // position the servo 

  val2 = analogRead (potpin2); 
  val2 = map (val2, 0, 1023, 0, 185);
  servo2.write (val2); 
  
  val3 = analogRead (potpin3);
  val3 = map (val3, 0, 1023, 0, 185); 
  servo3.write (val3);
  
  val4 = analogRead (potpin4); 
  val4 = map (val4, 0, 1023, 0, 185);
  servo4.write (val4); 
  
  val5 = analogRead (potpin5);
  val5 = map (val5, 0, 1023, 0, 185); 
  servo5.write (val5); 
  
  val6 = analogRead (potpin6); 
  val6 = map (val6, 0, 1023, 0, 185);
  servo6.write (val6);
}

There were a few semi-colons missing and a couple of the MAP() lines were missing. With those corrections this program should work with all 6 servos so I don’t understand your comment

the first problem is the servos are not declared and then son and so on.

…R

Wow, I dident know it was as simple as that, Im reading into it to much or something.

And how you lay out the code sketches is not the way im used to seing it, But i like it like that, Its much easyer and clearer your way.
Nice one, Thanks.

anyone had the same problem with the power supply ?

Powering one servo using an external power source seems to work fine, But when any more then one servo are conected ,Still only one servo will work through a potentiometer…

Is there any wiring diagrams that could show me what components i would need to make a break out board like the ones that drive the desk top robotic arms.

How do those 6 axis desktop robotic arms power all 6 servos without any problems ?

I dont want to just buy one, I want to make my own so to understand things better.

Im using 6 Hobby YM-2763 servos.

All you need to power several servos is a power supply or battery that can supply sufficient current and good connections i.e. NOT through a breadboard. Those are powerful servos which likely take around 2A each on startup. What power are you using?

Steve

What are the specs of the external power supply? Can it supply enough amps?

What are the specs of the servos? How many amps does each of them need?

Can you make a simple drawing showing how you have everything connected and post a photo of the drawing. See this Simple Image Guide

...R

i followed the wiring from the picture from fritzzz in the post up top.
It is not just a simple drawing to me.

And my power supply is a usb cord to a USB plug with the option of 1A or 2.4A, hhmmm could it be because it mA socket for power ?

I went and brought a switch mode power adaptor that has these specs.

Binding post output.
Output Voltage :3,5,6,12,13.8VDC
Output Current :2.5A max.
Dimensions :140(L) x 80(W) x42(H)mm.

FLCFLC:
i followed the wiring from the picture from fritzzz in the post up top.

I don't see any picture in an earlier Post.

In any case I believe it is a great idea (and I do it myself) to make your own diagram from your own project. Just doing that can show up things that had been overlooked.

...R

Why cant some one just help me to make some sort of break out board , Its starting to drag on this with no real answer.

I though the point of My own post was to ask questions, But now your asking me questions i have no idea about,
Im a compleete beginer.

I even tried to attatch a jpeg file and it jus kept timing out.

It might be easy for some off you but i feel like punching the computer screen.

FLCFLC:
Why cant some one just help me to make some sort of break out board , Its starting to drag on this with no real answer.

When I looked back over this Thread it seemed to me that you have already received (and acknowledged) a considerable amount of help.

However if you need help with making connections or choosing a power supply you have to answer some questions. Otherwise we have no idea where you have got to.

I realize it is frustrating for a newbie to have to wait 5 minutes between Posts, but that limit is there to deter spammers and it goes away after your 100th Post.

...R

FLCFLC:
I even tried to attatch a jpeg file and it jus kept timing out.

How big is the image file?
Keep it under 1M and make it png or jpg.
Tom... :slight_smile: