Multi servo

How can i run 10 servo with different speed
Plz help me... Send me code

(deleted)

@Melvingamit, I see that you are a new forum member.
Do yourself a favor, go to the top of this forum and read the post titled 'How to use this forum - please read'
It tells you all sorts of helpful things.

After you read it, you will understand why begging for code gets you no help.
Paying for code is one answer.
Writing your own code and asking for help is another.

But read the post titled 'How to use this forum - please read'

Melvingamit:
How can i run 10 servo with different speed
Plz help me... Send me code

You will have to explain what you mean by "run" a servo and what you mean by "with different speed". When you tell a hobby servo to move to a particular position it will move there as fast as it can. It will slow down when it gets near so it doesn't overshoot. One way to give the illusion of controlling speed is to break the movement down into tiny steps and add delays between steps. See File->Examples->Servo->Sweep for an example. To do this with multiple servos moving in different directions at different rates you will need to eliminate the delay() calls and use the millisecond timer (millis()) to set the rate at which you update the desired position.

Melvingamit:
Plz send the code to my email plz its regent

Whether it is urgent, or even if you don't need it before Christmas, it's not going to happen.

And it is very unwise to publish your email address unless you like getting deluged with spam.

...R

(deleted)

I'll do it for £499.99! :slight_smile:

£499.95! :sunglasses:

Melvingamit:
Plz send the code to me plz its regent

"regent" = king!

Obviously not GB, so of which country are you king? :astonished:

Paul__B:
"regent" = king!

Actually not. And the word may be more apposite than you thought :slight_smile:

"regent - a person appointed to administer a state because the monarch is a minor or is absent or incapacitated"
[Concise Oxford Dictionary] (my emphasis)

...R

(deleted)

Melvingamit:
Can anyone
tell me the code??

Have you carefully read all the Replies you have already received. If you discount the various humorous comments perhaps you can summarize what the others said?

...R

Robin2:
Actually not. And the word may be more apposite than you thought :slight_smile:

Certainly close enough! :roll_eyes:

The OP appears to be a few sandwiches short of a picnic. :astonished:

Or is he working with an airsoft bomb?

xl97:
Adafruit 16-Channel 12-bit PWM/Servo Shield - I2C interface : ID 1411 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits

Link corrected.

Good answer.

But I think he wants you to do the coding for him as well. Can you do that?

If we're in a bidding war, I'll do it for 80,769,000.00 Bolívar; price only valid for today since currency may drop in value tomorrow.

Melvingamit:
My code but all servo is running with same rate and direction.. I want to control all servo with different directions and different rate.. Can anyone tell what to do..

Look at how the servoSweep() function works in Several Things at a Time. Note, especially, that it does not us FOR.

Play around with it and see how to change the range and the timing.

Then think about how you can extend the idea to two servos.

...R

A good first step when you find yourself with three or more variables that have the same type and almost the same name and only differ by a number appended to the name: turn them into an array. Here I have done that for you. It will make the next steps much easier.

#include <Servo.h>
const byte SERVO_COUNT = 10;


Servo Servos[SERVO_COUNT];
const byte ServoPins[SERVO_COUNT] = {31, 32, 33, 34, 35, 36, 37, 38, 39, 40};


int time1 = 20;
int time2 = 20;


void setup()
{
  for (int i = 0; i < SERVO_COUNT; i++)
  {
    Servos[i].attach(ServoPins[i]);
  }
}


void loop()
{
  for (int angle = 0; angle < 180; angle++)
  {
    for (int i = 0; i < SERVO_COUNT; i++)
    {
      Servos[i].write(angle);
    }
    delay(time1);
  }


  for (int angle = 180; angle > 0; angle--)
  {
    for (int i = 0; i < SERVO_COUNT; i++)
    {
      Servos[i].write(angle);
    }
    delay(time2);
  }
}

The next step is getting the servos to step at different speeds. To do that you have to abandon 'delay()' and use the example File->Examples->02.Digital->BlinkWithoutDelay as your guide. EACH servo will need a delay value and a variable to record when the last move started. Those will be two more arrays:

unsigned Delays[SERVO_COUNT];  // Milliseconds between steps
unsigned long LastStepTime[SERVO_COUNT];

Now each servo needs a current position and target position for the current move:

unsigned CurrentPosition[SERVO_COUNT];
unsigned TargetPosition[SERVO_COUNT];

In setup() you should initialize your target positions and step times.

void setup()
{
  for (int i = 0; i < SERVO_COUNT; i++)
  {
    CurrentPosition[i] = 90;
    Servos[i].write(CurrentPosition[i]);
    Servos[i].attach(ServoPins[i]);
    TargetPosition[i] = random(181);  // Number between 0 and 180
    Delays[i] = random(10, 100);  // Delay between steps of 10 to 99 milliseconds
  }
}

And in loop() you just go through all of the servos and move any whose time has run out by one step toward the target position:

void loop()
{
  unsigned long currentMillis = millis();


  for (int i = 0; i < SERVO_COUNT; i++)
  {
    if (currentMillis - LastStepTime[i] >= Delays[i])
    {
      // Time for the next step
      LastStepTime[i] += Delays[i];
      if (CurrentPosition[i] < TargetPosition[i])
      {
        // Move toward higher positions
        CurrentPosition[i]++;
        Servos[i].write(CurrentPosition[i]);
      }
      else if (CurrentPosition[i] > TargetPosition[i])
      {
        // Move toward lower positions
        CurrentPosition[i]--;
        Servos[i].write(CurrentPosition[i]);
      }
      else
      {
        // We have reached the target position
        // Pick a new target
        TargetPosition[i] = random(181);  // Number between 0 and 180
        // and a new speed
        Delays[i] = random(10, 100);  // Delay between steps of 10 to 99 milliseconds
      }
    }
  }
}

@johnwasser

You're a good guy John! :slight_smile:

xl97:
You're a good guy John! :slight_smile:

And I'm not because I thought it would be good for the OP to do some of his own thinking?

...R