My 6V servo controlled with Arduino

I bought 120G EXI Servo B1226 servo last year and as a beginner I didn't know as much about electronics as I do now so I went ahead and connected my servos to the arduino's 5V supply. At another point in time I used an external 6V adapter for supply and 5V I/O to control from arduino. Well, I gave up on the use of the servos because not only were they behaving inaccurate, they also didn't really follow the positions I gave them. Now that I know a bit more about electronics I know that Arduino's 5V supply would need a 5 V Servo for accurate and proper control. My servo being 6V and power supply being 5 or 6 V means my arduino need to send 0-6V pulses to get the servo's pot to behave properly OR I could say that 5v/6v * 100 = 83.33 % of a 360 % rotation (this servo has 360 % full rotation control) which means that using 5 V I can get a max rotation of 300 %.

I hope I understand this correct. Now my question is: Am I suppose to use resistors with my servo normally or connect them directly to arduino? 2nd question, what can I do to get the full 360% control of my servo using arduino's 5V? It would be really inaccurate to use 5 V to control a 6 V servo because of the POT inside.

The control pulse for a servo is usually 5V. So with a separate 6V supply for the servo motor, it should work.

The rotation angle is not determined by voltage. It's determined by pulse width. The servo's internal controller compares the target angle indicated by the pulse width with the current position indicated by the pot. Then it moves in the necessary direction (if the current angle is not already correct).

There is a servo library for the Arduino that should generate the correct pulses. (I've never used it.) I'm not sure what will happen if you use that standard library with a 360 degree servo.

Do you have the datasheet for the servo? It should give you the necessary details. If you have a 360 degree servo, it's especially important to get the information on how to control it.

Most servos don't go 300 (or 360 degrees) degrees. I know sometimes servos are modified, but pots don't rotate that far either, so actually I don't know how they sense the actual angle. (Maybe it uses a digital rotary encoder.) You could gear it up so that 180 degrees of motor & pot rotation is converted to 360 degrees of gear-rotation. But but like I said, I don't know how it's normally done.

I hope I understand this correct.

No, you don't. servos need an external power supply. Powering servos from the arduino will cause the arduino to brownout and reset. Your servo will only rotate more than ~180 deg. if it is a continuous rotation servo, or a sail winch servo. Below is the typical way to connect a servo to an arduino. Bottom is some code for testing a servo.

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  } 
}

That connection pic of the kat which zooms should be lodged somewhere in the header of every forum page for everyone to see all the time. It is probably the single-most-used answer to servo-related forum questions! I have taken the liberty of saving it and will use it, with attribution to zk, in my answers too, if @zoomkat you have no objection to that.

No problem, you can use the diagram as you need to help others. It has two important concepts, external power supply and connected grounds.

Each of these servo cost me 16$ and I bought 2 of them when I begun using servos last year. I was about to throw them out out of frustration because I can really figure out how to control them properly...the 180 degree servos are simple but this I can't figure out. 120G EXI Servo B1226 is the servo and this is the url: 120G EXI Servo w/ Continuous Rotation B1226 (Great for RC Boats) EXI-Servo-B1226

Found this in the reviews, not sure what it means:

It's a boat wench Servo. Which means it can rotate 360 degrees but it has a 8.5 turn Potentiometer. Which means it only rotates 8.5 turns from one stop to the other. However it is incredibly east to convert.

  • No cutting
  • No soldering

All you have to do to convert it to continuous is remove the gear side cover and remove a clip with your fingernails. Then rotate the pot until it's centered. Because it's an 8.5 turn pot you can use the pot it already has. Thats it your done. The things has more than enough torque for robot drive systems. My application was to have four servos drive 4 wheels and a 6 ibs bot. The wheel is is 3-4 inches for proper speed. I can easily take more load then that. The horn to use is the one for the B1228 which they sell separately just search for B1228 horn.

Your servo appears to be a sail winch servo that has ~8 turns of rotation. Specifically what do you what your servo to do?

I want to have control in 360 degree angle. Even 180 degree angle will do. Can it do that?

twirap:
I want to have control in 360 degree angle. Even 180 degree angle will do. Can it do that?

You should be able to rotate the servo 360 deg. When your servo is appropriately powered and connected to the arduino, you can use the below servo test code to experiment.

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  } 
}

Just remember, if it's a winch servo, it's resolution will be spread all around that 8 turns of rotation, so if using only one rotation (360degrees) the resolution will be extremely coarse.

You need a standard servo if precise positioning is what you are after.

// Per.

So basically the difference between a normal servo and a winch servo is that the 0-180 range for a winch servo is actually spread throughout 8 turns 360*8/180 to get the angle per 1 integer where as in a normal servo of 180 degrees, each angle corresponds to 1 integer.

This means the normal servo is much more accurate than this winch servo. My servo gives roughly 16 degree movement for 1 unit of servo.Write(). The normal 180 degree servo would give 1 degree movement for 1 unit of servo.Write(). Each time the arduino is powered on, these servos start spinning to some default position...I feel like this 32$ was a waste of money since 16 degrees is a really big inaccuracy per unit of servo.Write(). I got them because they were fairly high-torque servos. Maybe I should ditch them for now and save them for some other use like a valve turning or use them to drive a robot. Is there no servo out there which gives only 360 degree control? A lot of the 180 degree control ones don't really have that much torque.

Thank you for the code. I will try experimenting with it to see if I can evade a new purchase of servos for my project. I have never really seen this type of code especially with the Micro method that you have. Normally, the code I found online was for the 180 degree servos where the range is 0-180. I really hope there is some way for me to use these servos with decent accuracy because I need their 360 degree ability for my project.

So basically the difference between a normal servo and a winch servo is that the 0-180 range for a winch servo is actually spread throughout 8 turns 360*8/180 to get the angle per 1 integer where as in a normal servo of 180 degrees, each angle corresponds to 1 integer.

This means the normal servo is much more accurate than this winch servo. My servo gives roughly 16 degree movement for 1 unit of servo.Write(). The normal 180 degree servo would give 1 degree movement for 1 unit of servo.Write(). Each time the arduino is powered on, these servos start spinning to some default position...I feel like this 32$ was a waste of money since 16 degrees is a really big inaccuracy per unit of servo.Write(). I got them because they were fairly high-torque servos. Maybe I should ditch them for now and save them for some other use like a valve turning or use them to drive a robot. Is there no servo out there which gives only 360 degree control? A lot of the 180 degree control ones don't really have that much torque.

Thank you for the code. I will try experimenting with it to see if I can evade a new purchase of servos for my project. I have never really seen this type of code especially with the Micro method that you have. Normally, the code I found online was for the 180 degree servos where the range is 0-180. I really hope there is some way for me to use these servos with decent accuracy because I need their 360 degree ability for my project.

Also, I saw that Attiny84 or Attiny85 operate on 3.3 V instead of 5V like atmega 328. So if I have a regular servo which takes 0-5V for input then wouldn't this be an issue if I was controlling the servo with Attiny since it can only provide a max of 3.3V as input to servo.

twirap:
Also, I saw that Attiny84 or Attiny85 operate on 3.3 V instead of 5V like atmega 328. So if I have a regular servo which takes 0-5V for input then wouldn't this be an issue if I was controlling the servo with Attiny since it can only provide a max of 3.3V as input to servo.

When in doubt, read Datasheet!

Tiny-voltage.png

Does that mean if I provide it 5 V input to power the Attiny84 then it can output 5V as input to a servo? remember how we just talked in this thread about how most servos take 5 V for input.

Also, I think I may not be doomed with this 8 rotation servo. 16 degrees per 1 unit isn't too bad for my project so it will do. I will play around with the servo code posted.

A Servo will work with a input signal with an amplitude from 3.3V to 5V without any problems.

A servo does not get told which angle it needs to go to. The servo signal is a pulse that is between 1 millisecond and 2 millisecond long. The pulse is repeated each 50 milliseconds.

A 1ms pulse puts the servo at one end, a 1,5ms puts it in the center, and a 2ms put it in the opposite end. The mechanical servo construction then decides if the resolution is spread over 180 degrees, 360 degrees, or even 8 turns. It does not matter for the Arduino.

// Per.

zoomkat:

twirap:
I want to have control in 360 degree angle. Even 180 degree angle will do. Can it do that?

You should be able to rotate the servo 360 deg. When your servo is appropriately powered and connected to the arduino, you can use the below servo test code to experiment.

// zoomkat 10-22-11 serial servo test

// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n = readString.toInt();  //convert readString into a number

// auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

readString=""; //empty for next input
  }
}

I am REALLY confused with what is going on in this code...I understand this code: Arduino Playground - HomePage

where 0-180 is the entire range and you can write a value between 0-180 and your servo will go there. But now we have a winch servo which has 0-2880 range. I don't know what this writeMicrosecond() method is because I am only familiar with serv1.write(value in the range);

Zapro:
A Servo will work with a input signal with an amplitude from 3.3V to 5V without any problems.

A servo does not get told which angle it needs to go to. The servo signal is a pulse that is between 1 millisecond and 2 millisecond long. The pulse is repeated each 50 milliseconds.

A 1ms pulse puts the servo at one end, a 1,5ms puts it in the center, and a 2ms put it in the opposite end. The mechanical servo construction then decides if the resolution is spread over 180 degrees, 360 degrees, or even 8 turns. It does not matter for the Arduino.

// Per.

OOOOOOOOOOOO I see what you're saying. So you are saying basically that any voltage amplitude of 3.3-5V is interpretable or readable by the servo and the width of the pulse itself which consists of the 3.3 or 5V amplitude tells the servo where to go. I understand now. I vaguely remembered from 2 years ago's reading that there is a pulse sent prior to the position or angle pulse which tells the servo "get ready because instructions are coming" You said the pulse is repeated each 50 ms and this explains how my servos are often twitching every few milliseconds towards a certain position. This 50 ms pulse must be telling them every 50 ms that "hey you're kinda off the mark you're suppose to be at so go back to your position" and that's why they twitch a bit.

You know how in that servo code there is the setting of initial servo position before we start writing positions to it, what purpose does the initial position setting do if you could just do serv1.write(value) instead? My servos always return to some position when I power them up. Is this initial position setting that initial position that they go to as soon as they are powered?

twirap:
OOOOOOOOOOOO I see what you're saying. So you are saying basically that any voltage amplitude of 3.3-5V is interpretable or readable by the servo and the width of the pulse itself which consists of the 3.3 or 5V amplitude tells the servo where to go. I understand now. I vaguely remembered from 2 years ago's reading that there is a pulse sent prior to the position or angle pulse which tells the servo "get ready because instructions are coming" You said the pulse is repeated each 50 ms and this explains how my servos are often twitching every few milliseconds towards a certain position. This 50 ms pulse must be telling them every 50 ms that "hey you're kinda off the mark you're suppose to be at so go back to your position" and that's why they twitch a bit.

Exactly!

Thought I might share that to anyone new reading on servos on this forum. Now back to the 2 questions I have left:

Would the range be 0-2880 in my code for my servo?
Is this initial position setting the first position servo goes to as soon as it is powered?

This is kind of interesting to see how servos work from inside....I am considering taking some servo's apart to use their control circuit to control things other than the motor they control.