continuous servo motor trouble

I’m trying to use four push buttons to control two servo motors. While a push button is held down the motor rotates and when its released the motor stops. the second button rotates the motor in the opposite direction. The code works fine for the normal servo, but the continuous servo will not stop, only change direction? Servo A is the continuous motor.

#include <Servo.h>

const int buttonPin = 1;

const int buttonPin2 = 2;

const int buttonPin3 = 4;

const int buttonPin4 = 5;

int buttonState = 0;

int buttonState2 = 0;

Servo servoA;

Servo servoB;

int position = 0;

void setup() {

servoA.attach(3);

pinMode(buttonPin, INPUT);

pinMode(buttonPin2,INPUT);

servoB.attach(6);

pinMode(buttonPin3, INPUT);

pinMode(buttonPin4, INPUT);

}

void loop() {

buttonState = digitalRead(buttonPin);

buttonState2 = digitalRead(buttonPin2);

if(buttonState ==HIGH){

servoA.write(position++);

delay(5);

}

if(buttonState2 == HIGH){

servoA.write(position–);

delay(5);

}

buttonState = digitalRead(buttonPin3);

buttonState2 = digitalRead(buttonPin4);

if(buttonState ==HIGH && position < 180){

servoB.write(position++);

delay(5);

}

if(buttonState2 == HIGH && position > 3){

servoB.write(position–);

delay(5);

}

}

Hi,

Two things:

(1) Pins 0 and 1 are used for sketch upload communication. Don't use 1.

(2) Continuous rotation servos will only stop with a value near 90 degrees. You will need to experiment to find the best value for any specific servo..

See: https://arduino-info.wikispaces.com/Servos

(scroll down to "Robot Servos: )

thank you. After more research i figured that out. could you point me in the direction of just making it stop at 180 degrees? that should work fine for the project specifications

I just need to get the thing to stop rotating somehow. It just keeps going!

Hi,

I just need to get the thing to stop rotating somehow. It just keeps going!

Sorry, You don't understand..

NOTE: Servos that can rotate continuously have no absolute position information available. The exact Pulsewidth that makes the motor stop is usually not exactly equal to the "90 degrees" value of a positional type servo. If you want your robot to stop completely you will have to determine the needed value. Values of less than or greater than 90 will make the servo run in one direction or the other, at different speeds.

Use this code example:

https://arduino-info.wikispaces.com/YourDuinoStarter_ServoPotPosition

You will be able to make the servo go clockwise, stop, go counterclockwise.

If you want to know the values, add a "print" statement after " myservo.write(Position); " so you can see the values..

okay so since its continuous there's no way of determining what angle it's at?is that right? would there be a way to make in turn in one direction for just a certain amount of time and then stop? so its not dependent on the angle at all

So the way a normal servo works is you tell it what angle position you want it to go to. It has a feedback mechanism that tells it what angle position it's currently at, and it uses the difference between where it is and where you told it to go, and calculates the speed and direction from that. If you tell it to go to an angle position that is close to where it is, the speed will be slow. If you tell it to go to an angle position way across the spectrum, it moves faster.

A continuous rotation servo has the feedback mechanism broken. The feedback mechanism is set to send a fixed signal -- generally very close to 90 degrees. The servo thinks it is always at that angle position. If you tell it to go to that angle position, it thinks it is already there, so it stops.

If you want to get it to stop, you need to find out the position that the feedback mechanism is set to. Try 90. If you're lucky, it will stop. If you're not lucky, it will move slowly in one direction or the other. In which case, try 89 or 91, or other angle positions. If you try an angle position that is far away from the set point, it will rotate fast. If it is close, it will rotate slowly.

To make the motor run at max speed, tell it to go to angle position 0. To make it go max speed in the other direction, tell it to go to angle position 180. To make it stop, tell it to go to the set point. Which will be close to 90.

sorry i've never used a continuous servo before. so if it's calibrated correctly it will stop if the angle is set to 90 degrees? so you could set it equal to 0 degrees for a certain amount of time and it would run at max speed in one direction for a set amount of time then set the speed equal to 90 and it would stop?

gcdedf114:
sorry i've never used a continuous servo before. so if it's calibrated correctly it will stop if the angle is set to 90 degrees? so you could set it equal to 0 degrees for a certain amount of time and it would run at max speed in one direction for a set amount of time then set the speed equal to 90 and it would stop?

Yes

gcdedf114:
sorry i've never used a continuous servo before. so if it's calibrated correctly it will stop if the angle is set to 90 degrees? so you could set it equal to 0 degrees for a certain amount of time and it would run at max speed in one direction for a set amount of time then set the speed equal to 90 and it would stop?

Or you could just use a real servo, because what you suggest may work for a while but should the supply voltage change then the speed of the "servo" will change.

By the way, how is the "servo" powered ?
Not from an Arduino pin, I hope, as it very likely exceeds the current that can safely be delivered.