Re: Problem with servos

Hi every one,

I am absolutely going crazy trying to make this project to work.

I am using Audrino Nano. I have written code for 5 servos to move using five pins and a switch to drive the servos from 45 to 135 degrees, and back. I need to add a second switch that would make only 3 servos to move. Please help me!!!!!

Here's my code:

#include <Servo.h>
int pos = 45;

// Defining servos

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;

void setup (){
pinMode(6, INPUT);
pinMode(7, INPUT);

//Servo pins in PWM

servo1.attach(2);
servo2.attach(3);
servo3.attach(4);
servo4.attach(5);
servo5.attach(6);
}
void loop(){
if (digitalRead(6) == HIGH && pos < 135) {
pos++;
servo1.write(pos);
servo2.write(pos);
servo3.write(pos);
servo4.write(pos);
servo5.write(pos);
delay(15);
}
if (digitalRead(7) == HIGH && pos > 45) {
pos--;
servo1.write(pos);
servo2.write(pos);
servo3.write(pos);
servo4.write(pos);
servo5.write(pos);
delay(15);
}
}

Do you have a common ground for all the servos, the power supply and the Arduino?

Please remember to use code tags when posting code.

Yes all servos have a common ground and they work fine. All I need is to see if some one can help me to to wrote a code that servos 3,4 and 5 would move from 45 to 135 degrees.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom ... :slight_smile:

azflyer:
Yes all servos have a common ground and they work fine. All I need is to see if some one can help me to to wrote a code that servos 3,4 and 5 would move from 45 to 135 degrees.

As stated that's really easy. Just take out the writes to servo1 and servo2.

But I guess you mean something else. You seem to have 2 switches already or at least you're using two pins. Do you plan to add a third? Or two more? Or if that is one switch where is the circuit diagram that shows how it is connected?

What exactly are the switch conditions that will make 3 servos instead of 5 servos go from 45-135 and what conditions make them go back from 135-45? And what is happening to the other 2 servos while they're doing it?

Steve