1

I am trying to make autonomous hexapod with an Arduino Mega board. I have followed tripod mechanism of hexapod movement. First I could control simultaneously legs (0, 2, 4) and (1, 3, 5) separately but whenever I tried to combine both i.e control 6 legs at a time I could not see any movement in the hexapod. Even in the IDE I am not getting any error.

I have connected the legs (0 to 5) to signal pins (2 to 7) respectively. I have connected a common +5v voltage and common ground voltage to individual legs using a breadboard. Can anyone give me a proper solution to overcome this issue and further would like to know how to control multiple servos and source code for it?

Here is my Arduino source code for controlling 6 servo motors.

#include <Servo.h>
Servo myservo[6]; 
int f=0;// create servo object to control a servo
//[0] -tibia , [1] -femur , [2] -coxa motors
void setup() {
  myservo[0].attach(2);
  myservo[1].attach(3);
  myservo[2].attach(4);
  myservo[3].attach(5);
  myservo[4].attach(6);
  myservo[5].attach(7);
}

void loop() {
  //alternatively making hexapod stand at its place
  //f is just flag variable to make it stop
  if(f==0) {
    myservo[0].write(130);
    myservo[2].write(130);
    myservo[4].write(90);
    myservo[1].write(130);
    myservo[3].write(90);
    myservo[5].write(0);
    f=1;
  }
}

Note the values that are added above are calculated separately for individual legs to mount legs on ground.

3
  • 2
    If you set your code to control 6 servos, does it work when you only connect 3 servos? If it does, then the problem may just be that your power supply is not strong enough to power 6 servos. Commented Dec 22, 2017 at 18:57
  • @EdgarBonet thank you it works fine when it connected to external power supply
    – Likhith R
    Commented Dec 27, 2017 at 10:56
  • I want to control 18 servos and based on your code I would add in 14 more servo objects. Is there a final code that you already finished with the 6 servos?
    – Ecko
    Commented Mar 7, 2018 at 5:51

2 Answers 2

2

The Arduino Mega can handle at most 40mA on the I/O pins, and 200mA on the 5V/GND pins. Six servos will draw far more current than the max of 200mA. You could try hooking up the servo power to a separate power source and the data pins to the Arduino. Hope this helps!

1

in the odd case that you are actually powering your (small?) servo's directly through the arduino : you'll need an external power source for your servo's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.