Basic programming Continuous servo

Hey

I have made a good hardware composition where the servo is connected on the right way with the arduino uno. The problem that I encounter is that I can’t program in code so that the servo keeps turning in the same direction continuously. Can someone show some simple code to do this. For programming I can make the servo object, attach the servo object to the right pin but then I am stuck in the write method of the servo object. I searched the internet and found only how to make it turn forward and then back. That’s not what I need. It needs to keep turning in the same direction because it is for a car robot that I want to program the servo for.

Do you have a 360° servo?

Hey

Yes I think so. It’s the one below:

The web search phrase "arduino continuous servo" turns up many tutorials. First hit:

This simulation uses180 degree servo commands to indicate what a 360 degree servo would do.

The documentation for the servo in question gives exactly the value ranges for movement and the 1500 microsecond value for stopping.

what does the servo do?

assuming you've tried at least 2 different values, it should have rotated with one of them

Yeth. That co es back as a continuous rotation servo.

Use the code in @xfpd's simulation in #5 and your servo should go CW and CCW at two rates each, and be close to or actually stopped with the 90 degree button.

Or just

void loop() {
  servoWrite(135); // spin one way
  delay(2777);     // for awhile 

  servoWrite(90);  // stop, or nearly
  delay(777);     // for awhile

  servoWrite(45);  // spin the other way
  delay(2777);     // for awhile
}

Tell us what happens.

a7

Hey

The code that you posted in post above had this as result: turns slowly in a direction, turn fast in the same direction, stops and keeps repeating this 3-steps on and on.

Back at you.

Now get empirical. The number makes the servo turn. Numbers between 0 and 180 should make it go from very fast in one direction alla way to stopped and then to very fast in the other direction.

Your report makes no sense; 90 should be stopped, higher numbers for one direction faster as they are greater and greater than 90, lower numbers for the other direction, faster as the numbers are less and more less than 90.

Try just one servo.write() call by itself and tinker with the number.

void loop() {
  servo.write(90);  // between 0 and 180
}

First: what does 90 give you?

a7

Hey

With that simple code gives 90 me: turns in same direction(clockwise) continuously , slow speed first and then speeding up, go back to slow speed again and speeding up again, and so on. And so on.

Sry, that makes no sense.

If what you claim is true, I have no idea what's happening.

Post the code. Don't just say what it is or what yiu did.

a7

what is the range of values?

what happens with servo.write(360);?
what is the max value of the argument

Google broken?

void Servo::write(int value)
{
  if(value < MIN_PULSE_WIDTH)
  {  // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
    if(value < 0) value = 0;
    if(value > 180) value = 180;
    value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX());
  }
  this->writeMicroseconds(value);
}

a7

Show what you have. Those angles do not map to those actions.

Write three sketches. Sketch one contains.

  servoWrite(135); // spin one way

Sketch two:

  servoWrite(90);  // stop, or nearly

Sketch three:

  servoWrite(45);  // spin the other way

Although I am sure @alto777 meant to write

  servo.write(x);  // 0 .. 180

in all cases.

a7

Who??? jkl

My examlke sketch in #8 bungled the calls - sounds good but isn't what is needed.

servo.write() != servoWrite()

There is no servoWrite() function in evidence.

a7

I missed the "." in my copy/paste. Sorry.

I used the sketches separately:

This code does this: rotates fast continuously counter-clockwise

Sketch two:

  servo.write(90);

This code does this: goes slow, speeds up, go slow, speeds up, and so on

Sketch three:

  servo.write(45);

This code does this: rotates fast continuously clockwise