robotic arm with potentiometer

Hello guys, I tried to make a robotic arm from meArm with sg90 servos. First, I try to modified a code from arduino app called “knob” to control 4 servos at the same time. But, when everything wired perfectly, the servo goes wild. I’ve read another forum which said I have to add another external power supply for the servo, I’ve done that, but the servo still goes wild. Any solution?
Thanks

this is the code

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin1 = 0;  // analog pin used to connect the potentiometer
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;

int vala;    // variable to read the value from the analog pin
int valb;
int valc;
int vald;

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.attach(10);
  myservo.attach(11);
  myservo.attach(12);
}

void loop() 
{ 
  vala = analogRead(potpin1);            // reads the value of the potentiometer (value between 0 and 1023) 
  vala = map(vala, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(vala);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 

  valb = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023) 
  valb = map(valb, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(valb);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 

  valc = analogRead(potpin3);            // reads the value of the potentiometer (value between 0 and 1023) 
  valc = map(valc, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(valc);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 

  vald = analogRead(potpin4);            // reads the value of the potentiometer (value between 0 and 1023) 
  vald = map(vald, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(vald);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
}

Post your code, post your schematic.

AWOL:
Post your code, post your schematic.

I just add the code, thanks

So now just add your schematic.
The two are linked. It is a waste of time just posting one.

Edit :- read up on how to use more than one servo. Each require its own name.

You only have one servo object. Did you mean to do something like this:

Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;

.... and then....

 myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(10);
  myservo3.attach(11);
  myservo4.attach(12);

Grumpy_Mike:
So now just add your schematic.
The two are linked. It is a waste of time just posting one.

Edit :- read up on how to use more than one servo. Each require its own name.

I just add the schematic but it's not very good because i'm a beginner:) thanks

JimboZA:
You only have one servo object. Did you mean to do something like this:

Servo myservo1;

Servo myservo2;
Servo myservo3;
Servo myservo4;




.... and then....




myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
 myservo2.attach(10);
 myservo3.attach(11);
 myservo4.attach(12);

I forget about that, thanks. I tried using this code, but the servo still not move. Any solution?

Did you remember to change these lines:

myservo.write(vala);

.... to look like:

myservo1.write(vala);

etc?

I don't see a common ground in your diagram. The servo -ve, battery -ve and Arduino Gnd must all be joined together.

JimboZA:
I don't see a common ground in your diagram. The servo -ve, battery -ve and Arduino Gnd must all be joined together.

it's working!!! thanks!! but when I plug 4 servos with 4AA batteries power supply the servo didn't move. what can I do?

Perhaps the 4x servos together are calling for too much current.

JimboZA:
Perhaps the 4x servos together are calling for too much current.

so I just add more batteries?

You could give each servo a battery pack yep, or perhaps one pack between two.

But just to clarify, individual servos do work?

It is best to post your layout diagram and your code again to make sure you are doing things correctly.

rizkyyutama:
so I just add more batteries?

No.

JimboZA:
You could give each servo a battery pack yep, or perhaps one pack between two.

But just to clarify, individual servos do work?

At first I tried to control 2 servos, it works with a little vibrate. And then, I tried to control 4 servos and it didn't work. Any solution for the vibration? thank you so much

That kind of vibration is often power related. You didn’t say if each servo works correctly on its own? If they do, but then a bit of a problem with 2 and doesn’t work with 4, it’s likely you don’t have enough current.

If that’s the case you need more current from the battery pack or a battery pack per servo. Most people on the forum reckon on a 1A per servo budget (edit: although that’s probably too generous for micro servos with little load… I should measure mine)

Do you test with the servos mounted on the robotic arm? In this case they can influence each other by mechanical feedback, the only solution then are stepper motors.

DrDiettrich:
Do you test with the servos mounted on the robotic arm? In this case they can influence each other by mechanical feedback,

You mean sort of pulling against each other due to a mechanical design issue? I have a meArm and that's not the case. (But not sure what you mean.....)

What I did find though if I'm not careful, is that I can get a bit of a lock up if an arm is "over its pivot" if that makes any sense, ie not positioned correctly at the start in its correct operating area and sort of fighting itself. Can't explain that any better, sorry :slight_smile:

I also have MG995 metal gear Servos and can I use these servos for this project. Do you know whether this will work or not? Please give us the model and configuration of the Servos that you used.

Refaeliadria:
I also have MG995 metal gear Servos and can I use these servos for this project.

The meArm uses micro servos (about 20mm on the long dimension), the MG995 is a standard size, 40mm, servo.

Mine came packed with SG90, same as OP.

I have a build blog here, but never got round to finishing the coding. I decided to take an Arduino break last year and my son and I did our radio amateur licences instead.