Arduino Uno and 8 servos with sensor shield v 5.0

Hi,

I am in the process of making a robotic dog with Arduino Uno, and a sensor shield v5.0. I am having some problems with including everything in the code because I am still learning... I am trying to put 8 leg servos on the sensor shield for now just to get it walking, or at least all four legs moving. I already have 2 servos moving because of my previous code on it that did not include the sensor shield, but now work with the sensor shield on it. Could someone please tell me how to include everything in the code?

Could someone please tell me how to include everything in the code?

What code?

And what servos and how are you powering them? Generally if 2 servos "now work with the sensor shield" then it should be really easy to add the extra servos. What problems are you having?

If you want help you really need to give us something to work with.

Steve

The Sensor Shield v5.0 has a bunch of places to plug in servos. It looks like they have one for each data pin 0 through 13. Don't use 0 or 1 if you use Serial for I/O.

What other devices are you expecting to connect? It makes sense to plan ahead rather than to decide later to add something and find that the pins it needs are already in use.

Pins 2 or 3 can trigger interrupts so they should probably be left unused until you run out of other choices. Pins 10, 11, 12, or 13 are the SPI interface which is used for some peripherals. Start by using Pins 4, 5, 6, 7, 8, and 9 for six servos and then either 2 and 3 or 10 and 11 depending on if you use any SPI devices.

TheMemberFormerlyKnownAsAWOL:
What code?

slipstick:
And what servos and how are you powering them? Generally if 2 servos “now work with the sensor shield” then it should be really easy to add the extra servos. What problems are you having?

If you want help you really need to give us something to work with.

Steve

Hi, I am using 8 sg90 servos for the legs. For now I only want to get the legs moving, the previous code that I had for it was only for 2 servos without it being in the sensor shield. when I put those 2 servos in the sensor shield, they still worked with that code. Now I am trying to make a code that can work with all 8 servos on the sensor shield.

Here is my code, but I don’t think it is any good:

#Include
Servo1; //servo motor 1
Servo2; //servo motor 2
Servo3; //servo motor 3
Servo4; //servo motor 4
Servo5; //servo motor 5
Servo6; //servo motor 6
Servo7; //servo motor 7
Servo8; //servo motor 8

int i=100;
int j=70;

void setup() {

Servo1.attach(1); //attach
Servo2.attach(2); //attach
Servo3.attach(3); //attach
Servo4.attach(4); //attach
Servo5.attach(5); //attach
Servo6.attach(6); //attach
Servo7.attach(7); //attach
servo8.attach(8); //attach

Serial.begin(9600);

delay(1000);
}

void loop() {

{
Servo1.write(60); //write
Servo2.write(60); //write
Serov3.write(60); //write
Servo4.write(60); //write
delay(10);
}

}

Sorry the emoji is not supposed to be there..

I don’t think it is any good:

Any good for what ?

What should it do ?
What does it actually do ?

Why the extra { and } in loop() and why did you not post it using code tags after Auto Formatting it in the IDE ?

#Include <Servo h.> //full stop ?
Servo1; //servo motor 1 //not a proper declaration of a Servo object
Servo2; //servo motor 2
Servo3; //servo motor 3
Servo4; //servo motor 4
Servo5; //servo motor 5
Servo6; //servo motor 6
Servo7; //servo motor 7
Servo8; //servo motor 8

int i = 100;
int j = 70;

void setup()
{
  Servo1.attach(1); //attach  //do not use pin 1 in case you need to use the Serial interface for debugging
  Servo2.attach(2); //attach
  Servo3.attach(3); //attach
  Servo4.attach(4); //attach
  Servo5.attach(5); //attach
  Servo6.attach(6); //attach
  Servo7.attach(7); //attach
  servo8.attach(8); //attach
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  {
    Servo1.write(60);  //write
    Servo2.write(60);  //write
    Serov3.write(60);  //write  //name of the servo ?
    Servo4.write(60);  //write
    delay(10);
  }
}
Servo1.attach(1);
...
Serial.begin(9600);

Oops

johnwasser:
The Sensor Shield v5.0 has a bunch of places to plug in servos. It looks like they have one for each data pin 0 through 13. Don't use 0 or 1 if you use Serial for I/O.

What other devices are you expecting to connect? It makes sense to plan ahead rather than to decide later to add something and find that the pins it needs are already in use.

Pins 2 or 3 can trigger interrupts so they should probably be left unused until you run out of other choices. Pins 10, 11, 12, or 13 are the SPI interface which is used for some peripherals. Start by using Pins 4, 5, 6, 7, 8, and 9 for six servos and then either 2 and 3 or 10 and 11 depending on if you use any SPI devices.

Thank you!! I will definitely use that for my robot dog

UKHeliBob:
Any good for what ?

What should it do ?
What does it actually do ?

Why the extra { and } in loop() and why did you not post it using code tags after Auto Formatting it in the IDE ?

Thanks, that full stop is not supposed to be there, it changed a bit while I was preparing it... And sorry I am still a bit new to the Forum part...

It looks like what you meant to write is this:

#include <Servo.h>


Servo Servo1; //servo motor 1
Servo Servo2; //servo motor 2
Servo Servo3; //servo motor 3
Servo Servo4; //servo motor 4
Servo Servo5; //servo motor 5
Servo Servo6; //servo motor 6
Servo Servo7; //servo motor 7
Servo Servo8; //servo motor 8


void setup()
{
  Serial.begin(9600);


  Servo1.attach(2); //attach
  Servo2.attach(3); //attach
  Servo3.attach(4); //attach
  Servo4.attach(5); //attach
  Servo5.attach(6); //attach
  Servo6.attach(7); //attach
  Servo7.attach(8); //attach
  Servo8.attach(9); //attach
}


void loop()
{
  Servo1.write(60);  //write
  Servo2.write(60);  //write
  Servo3.write(60);  //write
  Servo4.write(60);  //write
  delay(10);
}

You will find that the code gets a lot cleaner if you use arrays instead of 8 separate objects with nearly the same name.

#include <Servo.h>


const int ServoCount = 8;


Servo Servos[ServoCount]; //servo motor 1
const byte ServoPins[ServoCount] = {2, 3, 4, 5, 6, 7, 8, 9};


const byte Position0[ServoCount] = {60, 60, 60, 60, 90, 90, 90, 90};


void setup()
{
  Serial.begin(9600);


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


void loop()
{
  for (int i = 0; i < ServoCount; i++)
  {
    Servos[i].write(Position0[i]);
  }


  delay(10);
}

johnwasser:
It looks like what you meant to write is this:

#include <Servo.h>

Servo Servo1; //servo motor 1
Servo Servo2; //servo motor 2
Servo Servo3; //servo motor 3
Servo Servo4; //servo motor 4
Servo Servo5; //servo motor 5
Servo Servo6; //servo motor 6
Servo Servo7; //servo motor 7
Servo Servo8; //servo motor 8

void setup()
{
 Serial.begin(9600);

Servo1.attach(2); //attach
 Servo2.attach(3); //attach
 Servo3.attach(4); //attach
 Servo4.attach(5); //attach
 Servo5.attach(6); //attach
 Servo6.attach(7); //attach
 Servo7.attach(8); //attach
 Servo8.attach(9); //attach
}

void loop()
{
 Servo1.write(60);  //write
 Servo2.write(60);  //write
 Servo3.write(60);  //write
 Servo4.write(60);  //write
 delay(10);
}





You will find that the code gets a lot cleaner if you use arrays instead of 8 separate objects with nearly the same name.


#include <Servo.h>

const int ServoCount = 8;

Servo Servos[ServoCount]; //servo motor 1
const byte ServoPins[ServoCount] = {2, 3, 4, 5, 6, 7, 8, 9};

const byte Position0[ServoCount] = {60, 60, 60, 60, 90, 90, 90, 90};

void setup()
{
 Serial.begin(9600);

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

void loop()
{
 for (int i = 0; i < ServoCount; i++)
 {
   Servos[i].write(Position0[i]);
 }

delay(10);
}




Hi sir, Sorry for the late reply... I have been playing around with the codes and I understand it a bit better now. Thank you so much for your help