Modded Servo, strange behaviour

Hey, this is a great place here. I'm the proud owner of a Arduino Deuamillanove . I've also bought a regular servo and modded it so it could move 360degrees.

The way I did this was simply remove the metal block preventing it from making a full 360degrees. What I need the servo to do is start at a position (moved by hand if need be) , then turn 360degrees and stop. Then turn again, etc..etc.

Here is my code:

#include <Servo.h> 

//Servo servo2;  // create servo object to control a servo 
Servo servo1;

//int pos = 0;    // variable to store the servo position 
//int flag=0;

void setup() 
{ 
  servo1.attach(9);  // attaches the servo on pin 9 to the servo object 
  //servo2.attach(6);
} 

void loop() 
{ 
  
   servo1.write(120);
   delay(1540);
   servo1.write(132);
   delay(500);  
  
}

Some lines have been commented out, I'm waiting to get this to work properly and then i can add on other servos (total of 6 in the end).

Through experimentation i've found that values below 130 move the servo clockwise. Values above 140 move it counter clockwise. 132 is the value i need to write in order for it to stop. I have a feeling this is only true for THIS servo, and will need to find these values again for the other 5. I think it's because when modding it, I didn't adjust the potentiometer (though it is still attached inside, not connected to the main gear though) . Is it necessary to adjust it, even now? If yes, how would i do that?

I don't have a problem actually finding those values, just takes time. The real main problem is with the bigger delay of 1540ms it does make a full circle the first time. Then it slowly increases, 370deg, 380deg, etc .. I don't understand why this is happening? I've tried adjusting the delay time but i either have it going too much or too little (it starts going backwards 350deg, 330deg ) . I did find a value where it was doing 360degrees exactly for about 5 turns, after that it would go either too much or too little. Is there anyway to control this at all , i dont even understand WHY it's doing this..any help, suggestions or even an idea as to what's happening would be greatly appreciated.

Lastly, my biggest worry here is that the delay im using will NOT be the same for the other servos, again i think this has to do with the pot, any ideas on how i could keep consistency ..the motors are required to move together so i can only give one delay for the motors.

Wow, that was a long post ...thanks again and its great to be on these forums, hoping to learn a lot!

Well, if you wanted 360 degrees, you could have left the servo unmodded, and used 4:1 gearing (2:1 I wouldn't recommend, because not all servos will rotate 180 degrees).

Your approach using timed turns is unlikely to yield consistent results for a number of reasons - if the voltage dips because the supply can't cope with the draw when you move all the servos at once, you may find the motors slow, so never reach 360 degrees.

You've lost (no, actually, you've removed) the feedback mechanism; you can't expect open-loop to work as consistently.

You could use limit switches (mechanical, optical..) or your own encoders.

Thanks for the quick reply AWOL. So my options are to connect the potentiometer back in again and use gears to allow it to move 360degrees ..or use the a limit switch or encoder? The problem with placing it back is I've already got a peice of metal to connect to the servo itself, placing gears in between would make the overall project more bulky.

Can you please elaborate on the limit switches or encoders? I've googled them both, though i must admit not for very long. What hardware is required and roughly how would they work with the arduino?

Lastly i forgot to ask this before, i read somewhere in the forums that you can control the speed by changing the value you .write() to the servo. I've played around with this using a for loop and writing a LOT of numbers, I can't understand what the upper limit is or even if 0 really is the lower limit. More importantly it does NOTHING for the speed, it continues to rotate at the same pace as when it started though it does change direction (at around 130) . So is it really possible to control the speed of an unmodded servo and how?

Thanks!!

For finer control, you should be able to write the actual pulse time you want to use.
Have a look at "Servo::writeMicroseconds"
This should get you closer to the mid-point stop position.
Alternatively, use "detach" to stop the servo.

Thanks again AWOL, detach also does work for stopping the servo.

I've been researching the options you presented and the gear one is definitely out, the servo needs to turn 360degrees and then maybe continue to rotate 360degrees in the same direction depending on some circumstances. If a proper servo were connected it could not provide infinite turns in the same direction. I think it was my fault on this one because i didn't explain it properly :frowning:

So i've really looked into the limit switch/encoder. Though this is probably the best option for me, the Duemilanove has 5 Analaog input pins, using a rotary encoder would use 2 of those pins. I got this from another person using a rotary encoder on these forums. I will need 6 rotary encoders, which need 12 pins ..starting to wish i bought the mega :stuck_out_tongue: Is there anyway of monitoring these servo's? I wish to use them as a leg on a moving robot, is this possible with servo's? thanks again guys!

I don't think you need an encoder. You could just use a limit switch.

If you're not clear on the idea of a limit switch, it would be a switch that activates when the moving part is in the desired location. For example, you could have a notch on a wheel that triggers the switch once per revolution. If you need to adjust the stop location, you could make the switch movable, or find a way to change the location of the pin or notch that activates the switch.