Programming Continuous Rotation Servos with Arduino

Filed Under: , , ,
Continuous Rotation Servos with Arduino

Programming Continuous Rotation Servos with Arduino

Having completed the stitched elements of my latest piece of work I’ve now moved on to constructing the mechanics that will support this embroidered pieces. This has involved learning how to programme continuous rotation servos with Arduino.

I’ve dabbled with Arduino in the past for fun so have a very basic grasp of the programming language required. However, my aim is to power four continuous rotation servo motors from the Arduino sweeping through 120 degrees in either direction at random which a little more complicated than anything I’ve done in the past.

A normal servo motor would be able to sweep through 180 degrees, or parts thereof, and whilst I might be able to increase it’s sweep using a system of gears it will always, at some point have to move back again. The continuous rotation servos allow me to programme them in such a way that they could move clockwise or ant-clockwise completely at random.

//positioning a continuous rotation servo
//using a delay to poistion the motor
#include <Servo.h>
Servo myServo;
void setup() { 
  myServo.writeMicroseconds(1500);  // Stop 

void loop() { 
myServo.write(1526); //C-Clockwise
myServo.write(1500); //Stop

Unlike a standard servo the continuous rotation servos can’t be positioned to 120 degrees and so I have had to use a delay as a timer to position the motors each time they are activated. The code above is an a example of how I have been positioning the motors at 120 degree intervals.

It’s not as straight forward as positioning a standard servo but with some patience and lots of trial and error I’ve just about worked out the appropriate delay to continually position the motors at 120 degree intervals now. This is then combined with the ‘random’ function and a series of ‘if/else’ queries in the Arduino.

I think I’ve nearly cracked it as you can see at the end of the video above!