Continuous Rotation Servo

hello everyone, i am new with arduino and i would like to ask for some help... i have arduino uno Rev3 and a SpringRC SM-S4303R - Continuous Rotation Robot Servo. What i want to do is: when i push a button my servo takes a clokwise turn from 0 degrees to 45 degrees and when i release the button i want my servo to return back to the same position (0 degrees). So because it is a full rotation servo i do not know hot to send it to 45 degrees.... :cold_sweat: any help???

Simple servo/button test code. Use pin 7 to control the servo and touch pin 4 to ground as the button.

//zoomkat servo button test 7-30-2011
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

pasi:
hello everyone, i am new with arduino and i would like to ask for some help… i have arduino uno Rev3 and a SpringRC SM-S4303R - Continuous Rotation Robot Servo. What i want to do is:
when i push a button my servo takes a clokwise turn from 0 degrees to 45 degrees and when i release the button i want my servo to return back to the same position (0 degrees). So because it is a full rotation servo i do not know hot to send it to 45 degrees… :cold_sweat: any help???

Yes, obtain a standard servo. A continuous rotation servo cannot be commanded to go to a specific position and stop, there is no way your arduino can tell what position it is at at any specific time. What you have now is a variable speed bi-directional geared motor, not a servo.

Lefty

I don't understand why they call it a servo when it has no feedback.

The_Unreasonable_Man: I don't understand why they call it a servo when it has no feedback.

That is because it starts life out as a complete standard servo, then they remove the internal geared feedback to the internal pot and also remove the mechanical end stops on the gear train, which then makes it a variable speed bi-directional geared motor drive. It has been a source of confusion and mistaken purchases every sense they started offering them. Not sure what they should call them instead?

Lefty

thank you all !! finally the servo was wrong‚Ķ i bought a new one (0 to 120 degrees) and it seems to work fine. So‚Ķ my project is: when i turn a switch to ‚Äúon‚ÄĚ the servo turns to 90 degrees. Bellow is the code that i wrote:

#include <Servo.h>

Servo myservo; // Define my servo

int button= 7 ; // define the button pin
int val=0 ; // set button state

void setup()
{
myservo.attach(9); // servo digital pin 9
pinMode(button, INPUT); // define pin mode
}

void loop()
{
val = digitalRead(button);
if (val==HIGH)
{
myservo.write(90); // Turn Servo Left to 90 degrees
}
else
{
myservo.write(0); // Turn Servo Left to 0 degrees
}
}

the problem that i have now is that sometimes the servo turns by itself without any command from me. There is no short-circuit. The connections are:

from black (servo) to gnd (arduino),from red (servo) to 5VDC (arduino),from white (servo) to pin number 9 (arduino)
from 3.3 VDC (arduino) to the one pole of the switch and the other pole of the switch to pin number 7 (arduino)

is there anything wrong?

zoomkat:
Simple servo/button test code. Use pin 7 to control the servo and touch pin 4 to ground as the button.

//zoomkat servo button test 7-30-2011

// Powering a servo from the arduino usually DOES NOT WORK.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

thank you so much!! itryed yours and it is perfect!

Note that powering a servo from the arduino supplys the minimum operating voltage for the servo, and when the servo moves, it may cause the arduino to reset on low voltage. Use a seperate power supply for the servo for best results.

from 3.3 VDC (arduino) to the one pole of the switch and the other pole of the switch to pin number 7 (arduino)

You need pull-down resistor at pin 7 to ground, to keep it ‚Äú0‚ÄĚ when switch release. Otherwise pin has ‚Äúundefined‚ÄĚ status.

Thanks to this form and all the replies I’ve gotten my continuous rotation servo working as I want using the code I put together below to drive my SM-S4303R servo at varying speeds both clockwise and anti-clockwise.
I did this with the standard Arduino servo library ‚Äď nothing fancy ‚Äď and feel free to comment and suggest improvement ‚Äď I‚Äôve had my Arduino about 1 month.

Thank you all ‚Äď I hope my code will be useful to future readers!

// Ian Schlueter // March 2013 //
//
// A sketch to control a continuous servo using 
// 1) two buttons, one incriments a state counter for rotate/stop, the other for direction of rotation
// 2) one analog sensor mapped to allow normal "zero to max" speed control regarless of direction
// 3) one three wire continuous rotating servo:  stop=90 : max clockwise=180 : max anticlockwise=0
//
//


#include <Servo.h>        //  load the standard arduino servo library

Servo servo1;             // create servo object
const int servo1Pin=3;    // constant servo 1 pin
const int rotStop = 92;   // send what value to servo to stop it?
const int ControlPin=A0;  // pin to map to control value for speed

const int but1Pin=4;      // pin for button 1
const int but2Pin=5;      // pin for button 2
int but1Count=0;          // global: button 1 initial counter value
int but2Count=0;          // global: button 2 counter counter value
int lastbut1Sensor=0;     // global: last reading of the button sensor -- so we don't act except once per press
int lastbut2Sensor=0;     // global: last reading of the button sensor -- so we don't act except once per press

const int freq1 = 50;     // how often to check the buttons 50ms*20=1s or 20 times a second
unsigned long timer1;     // Holds the next check time.


void setup() 
  {
    pinMode(but1Pin, INPUT);    // buttons are inputs
    pinMode(but2Pin, INPUT);    // buttons are inputs
    pinMode(ControlPin, INPUT); // analog controlPin 
    servo1.attach(servo1Pin);   // attach the servo to the servo pin
    timer1=millis();            // using the internal clock starting..... now....
//    Serial.begin(9600);       // serial data if needed, comment if not

  }



void loop() 
{// ******** BEGIN Main Event LOOP *************
  int rotSpeed;
    if (millis() >= timer1)
    {
      timer1 += freq1;
    }
  butSet();
  if (but1Count == 0)
    servo1.write(rotStop);
  else
  {
//  Serial.print("rotSpeed on Return=");   // use if you are questioning the return from getSpeed)
//  Serial.println(getSpeed(rotSpeed));    // 
  servo1.write(getSpeed(rotSpeed));        // write the speed from your analog input to servo1
  }

  
}


// ******** END Main Event LOOP *****************

// ******** Begin Functions

int butCheck()  //  Call this to serial print the button states, otherwise don't call it
 {
    Serial.print("State>");
    Serial.print(but1Count);
    Serial.print("<< -- BUT1 --- BUT2 -- >>");
    Serial.print(" state >");
    Serial.println(but2Count);
    
    
 } 
 
void butSet()   //  check the status of our buttons and act accordingly
{  
      int but1Sensor= digitalRead(but1Pin);       // local sensor variable
      int but2Sensor= digitalRead(but2Pin);       // local sensor variable

      if (but1Sensor != lastbut1Sensor)           // Has the button changed since last we looked?
      {
        if (but1Sensor == HIGH)                   // is the button HIGH?
        {
          but1Count++;                            // count it if it's HIGH
        }
        lastbut1Sensor=but1Sensor;                // tell the world we just got HIGH
      }
      if (but1Count >= 2)                         // check to see if the count is too high
      {
        but1Count=0;                              // and set back to zero if it is
      }
       if (but2Sensor != lastbut2Sensor)          // has the button changed since last we looked?
      {
        if (but2Sensor == HIGH)                   // is it HIGH?
        {
          but2Count++;                            // count it if it's HIGH
        }
        lastbut2Sensor=but2Sensor;                // tell the world we just got HIGH
      }
      if (but2Count >=2)                          // check to see if the count is too high
      {
        but2Count=0;                              // and set back to zero if it is
      }
}

int getSpeed(int loopSpeed) // Get the speed to set the servo at based on but2Count
{
   int controlValue = analogRead(ControlPin);          // read from the control pin                    
   switch (but2Count)                                  // our count can be zero or 1
   {                                                    
     case 0:                                           // if it's zero rotate clockwise
      loopSpeed=map(controlValue, 0, 1023, 92, 180);  // continuous rotation at a speed between 90(stopped) and 180(max)
      break;
     case 1:                                           // if it's one rotate anticlockwise
      loopSpeed=map(controlValue, 0, 1023, 92, 0);    // continuous rotation at a speed between 90(stopped) and 0(max)
     break;                                      
   }
   return loopSpeed;                                  // return the proper speed for the proper direction
}

buttoncontrol_continous_servo.ino (4.7 KB)

-- and feel free to comment and suggest improvement --

Look at #7 below:

http://arduino.cc/forum/index.php/topic,148850.0.html

7 -- Thank you for pointing that out. I missed a very valuable step :)

You can use a Rotary Position Sensor in combination with a continuous rotating servo to determine the current angle of the servo.

Ideally it would be best to create a Servo Wrapper class. This class could have a method to set angle, speed, and direction. It would then power the continuous rotating servo (with speed and direction provided) to the desired degrees. You could even create another method for number of rotations.

This would give you the best of both worlds, a 360 degree servo (specify angle), continuous rotation, and number of rotations.

http://hitecrcd.com/products/servos/robotic-servos/hsr-1425cr-continuous-rotation-servo/product http://www.digikey.com/product-detail/en/3382G-1-103G/3382G-1-103GCT-ND/1944267

The Continuous Rotation Servos do not turn in deegrees, they turn just left and right, like their name says, "Continuous Rotation"

You must use this sentences:

servo.writeMicroseconds(1500);     //stop

servo.writeMicroseconds(1300);     //turn right

servo.writeMicroseconds(1700);     //turn left

also are in the Servo.h