Go Down

Topic: Servos on Arduino Uno (Read 855 times) previous topic - next topic

dp22

I have to control 3 servos on an Arduino Uno. I have written the program and two of the motors seem to work but the third is not responding at all.
/*
Arduino Servo Test sketch
*/
#include <Servo.h>
Servo servoAngler; // Main brace angle servo
Servo servoStopper; // Arm Holding Servo
Servo servoTensioner; // Spring Tension Servo

void setup()
{
   servoAngler.attach(10); // servo on digital pin 10
   servoStopper.attach(6); // servo on digital pin 6
   servoTensioner.attach(3); //servo on digital pin 3
}

void loop()
{
   servoStopper.write(0);      // Turn Servo Left to 0 degrees
   delay(1000);                // Wait 1 second
   servoAngler.write(90);      // Turn Servo to center position (90 degrees)
   delay(1000);                // Wait 1 second
   servoTensioner.write(180);  // Turn Servo Right to 180 degrees
   delay(1000);                // Wait 1 second
   servoStopper.write(90);     // Turn Servo back to center position (90 degrees)
   delay(1000);                // Wait 1 second
   servoTensioner.write(0);    // Turn Servo Left to 0 degrees
   delay(5000);                // Wait 5 second
   servoAngler.write(0);       // Turn Servo Left to 0 degrees
   delay(1000);                // Wait 1 Second   
}

Any ideas as to why it wouldn't work? There is power going to the servo.

Anything Helps. This is my first time using this program

johnwasser

The code looks fine so I would guess that there might be a hardware/wiring error.

If you swap a working servo for the non-working servo does the problem follow the servo or stay with the I/O pin?  If it follows the servo the servo may be faulty.  If it stays with the I/O pin then perhaps the pin is bad and you should try another pin.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Grumpy_Mike

Quote
I have written the program and two of the motors seem to work but the third is not responding at all.

So are you going to tell us which one doesn't work or do we have to guess?

Swap the non working one to the pin of a working one. Does the problem stay with the pin or follow the motor?

dp22

I was talking about the the stopper servo, sorry about that. But I did test the servo and it does seem faulty. Is there any way for me to make all of the servos go through the program except have one of the function wired to pushing a button and then have the rest of the program to continue. For ex:

#include <Servo.h>
Servo servoAngler; // Main brace angle servo
Servo servoStopper; // Arm Holding Servo
Servo servoTensioner; // Spring Tension Servo

void setup()
{
   servoAngler.attach(10); // servo on digital pin 10
   servoStopper.attach(6); // servo on digital pin 6
   servoTensioner.attach(3); //servo on digital pin 3
}

void loop()
{
   servoStopper.write(0);      // Turn Servo Left to 0 degrees
   delay(1000);                // Wait 1 second
   servoAngler.write(90);      // Turn Servo to center position (90 degrees)
   delay(1000);                // Wait 1 second
   servoTensioner.write(180);  // Turn Servo Right to 180 degrees
   delay(1000);                // Wait 1 second
   servoStopper.write(90);     // Turn Servo back to center position (90 degrees)    ----- I want this command to be wired on a push button.
   delay(1000);                // Wait 1 second
   servoTensioner.write(0);    // Turn Servo Left to 0 degrees
   delay(5000);                // Wait 5 second
   servoAngler.write(0);       // Turn Servo Left to 0 degrees
   delay(1000);                // Wait 1 Second   
}

Grumpy_Mike

Quote
But I did test the servo and it does seem faulty.

So that is the problem then.

Quote
Is there any way for me to make all of the servos go through the program except have one of the function wired to pushing a button and then have the rest of the program to continue.

That is way too imprecise to understand exactly what you want to do.
The way you have written it with all those long delays then there is no way it will respond to a push button. You will have to rewrite it properly using the technique shown in the blink without delay example.

Twice you haven't put the proper code tags in a post.
Select the code and hit the # icon, you can modify your existing posts now.

dp22

Not understanding what you mean by tags? Anyway you can show me?! :D

Grumpy_Mike

Quote
Select the code and hit the # icon,

That puts the code tags around your code. Try it.

dp22

/*
Arduino Servo Test sketch
*/
#include <Servo.h>
Servo servoAngler; // Main brace angle servo
Servo servoStopper; // Arm Holding Servo
Servo servoTensioner; // Spring Tension Servo

void setup()
{
   servoAngler.attach(10); // servo on digital pin 10
   servoStopper.attach(6); // servo on digital pin 6
   servoTensioner.attach(3); //servo on digital pin 3
}

void loop()
{
   servoStopper.write(0);      // Turn Servo Left to 0 degrees
   servoAngler.write(90);      // Turn Servo to center position (90 degrees)
   servoTensioner.write(180);  // Turn Servo Right to 180 degrees
   servoStopper.write(90);     // Turn Servo back to center position (90 degrees)
   servoTensioner.write(0);    // Turn Servo Left to 0 degrees
   delay(5000);                // Wait 5 seconds
[/color]   servoAngler.write(0);       // Turn Servo Left to 0 degrees
}


This is how I have chosen to write the program without delays. Any suggestions, the servos are not moving full speed?

Go Up