Now that I have my Rover 5 working I want to add a couple of servos with SRF06 ultrasonic sensors mounted on top of them. So I can let the SRF06 sensors detect an obstacle. The Arduino IDE comes with a simple servo library. One of the examples that comes with this library is a sweep example. It’s a very simple sketch that lets the servo move from 0 to 180 degrees. It uses the delay function to wait for the servo to reach it’s position. The library does not have any function to set the speed of the servo. Of course with some programming magic and making use of the millis function you can make a speed adjustable sweep sketch. But this is a bit to complex for a newbie like me.
After some searching on the Arduino forum I stumbled on the VarSpeedServo library. This library has a function to set the speed of the servo. Unfortunately it doesn’t come with any examples. But there was a sketch posted on the forum to sweep 4 servos. I copied the sketch and simplified it to just sweep 1 servo. You have to watch out with the speed settings. You can set the speed between 1 and 255, but no servo will be able to handle a speed of 255. After some testing I found that a speed of 30 was fast enough to let a servo sweep with the SRF06 on top of it. I wonder if this library will work with a continuous rotation servo. Would be very handy to control the speed of such a servo. Something that I will have to try out.
Here is the sketch to sweep one servo:
// speed controlled Servo Sweep // see: http://arduino.cc/forum/index.php/topic,61586.0.html // // Michael Margolis 4 August 2011 // edited by http://www.bajdi.com #include <VarSpeedServo.h> VarSpeedServo MyServo; // servo objects int servoSpeeds = 30; // sweep speed, 1 is slowest, 255 fastest) int servoMinPosition = 0; // the minumum servo angle int servoMaxPosition = 180; // the maximum servo angle void setup() { MyServo.attach(9); MyServo.slowmove(servoMinPosition,servoSpeeds) ; // start sweeping from min position } void loop() { // sweep the servos if( MyServo.read() == servoMinPosition) { MyServo.slowmove(servoMaxPosition,servoSpeeds) ; } else if( MyServo.read() == servoMaxPosition) { MyServo.slowmove(servoMinPosition,servoSpeeds) ; } }
Hi,
Can you send me your VarSpeedServo.h file.
I tried but would not find online.
Thank you
Regards
Leo
Hi, you can download the files here: http://arduino.cc/forum/index.php?topic=61586.0