Controlling 6 servos with 1 potentiometer

Im new to this, i cant find a code where i can control 6 servos with 1 potentiometer and need guide on how to connect all the 6 servos to a separate power supply

If you are you using the following Servo Motor of type SG90 (Fig-1), then you may ty the connection diagram of Fig-2?


Figure-1:


Figure-2:

  • Flesh this out a bit more . . .

thank you i will try this and you are correct i was using that exact servo motor type

i need them all to move in the same rotation as i control them with 1 potentiometer

Tank you and let me see your codes.

this code can only control 5 servos im looking for a code that can control 6

#include <Servo.h>

Servo servo1;
const int servo1PotPin =A0;
const int servo1Pin = 7; 
int servo1Value;



Servo servo2;
const int servo2PotPin =A0;
const int servo2Pin = 6; 
int servo2Value;



Servo servo3;
const int servo3PotPin =A0;
const int servo3Pin = 5; 
int servo3Value;



Servo servo4;
const int servo4PotPin =A0;
const int servo4Pin = 4; 
int servo4Value;


void setup() {

//multiple servos
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
servo4.attach(servo4Pin);

}

void loop() {
//Multiple servos - Move servo 180 degree mapping
servo1Value = analogRead(servo1PotPin);
servo1Value = map(servo1Value, 0, 1023, 0, 180);
servo1.write(servo1Value);

servo2Value = analogRead(servo2PotPin);
servo2Value = map(servo2Value, 0, 1023, 0, 180);
servo2.write(servo2Value);

servo3Value = analogRead(servo3PotPin);
servo3Value = map(servo3Value, 0, 1023, 0, 180);
servo3.write(servo3Value);

servo4Value = analogRead(servo4PotPin);
servo4Value = map(servo4Value, 0, 1023, 0, 180);
servo4.write(servo4Value);
  


}// loop end

Always use code tags when posting code. Please fix your post above, it is breaking forum rules. Please read the forum guide in the sticky post at the top of most forum sections.

If the servos are to be always in step, you don't need 6 Arduino pins, you can connect them to the same Arduino pin.

Please don't use "being new "as an excuse for not having read the forum guide before you posted.

2 Likes

How much is the typical current that is drawn by the PWM line of SG90?

its fixed now thank you

1 Like

You may try the following compact codes:

#include <Servo.h>

Servo myServo[6];

void setup() 
{
  for(int i = 0, j = 4; i < 6 ; i++, j++)
  {
    myServo[i].attach(j);
  }
}

void loop() 
{
  byte rotValue = map(analogRead(A0), 0, 1023, 0, 179);
  for(int k = 0; k < 6 ; k++)
  {
      myServo[k].write(rotValue);
  }
  delay(1000);
}

I wasn't able to find a figure in any data sheet, but it's a high impedance input, so the current should be negligible.

1 Like

One source says that it is usually in the range of uA; some other source says that it is few mA. Anyway, six servos, perhaps, could be tied at the same DPin and subject to testing .

thank you for this code bro it worked now

btw should i use a separate power supply for the potentiometer or arduino as the power supply for potentiometer is fine?

Which code - sketch of post #11?

This is fine to use 5V of UNO for te bias voltage of Pot1.

can the 5v batt handle all the 6 SG90 servos or should i add another batt

Try wth 5V 1000 mAh AH Battery and see how long it lasts.

may i know what is this called and what is it for?

This is 5V 1000 mAh power supply which I have found from net.

1 Like