Tuesday, November 8, 2011

Arduino - Continuous Rotation Servo

As part of my usual trawl around the Internet to learn a bit about electronics I came across the following page on Maker Wiki page.


It explains how to modify a servo so that it can rotate continuously clockwise and anti-clockwise.  Since I bought a pack of 4 servos on ebay I decided I would see if I can get this to work with my really cheap servos.

I took apart the servo and found it was a bit different.  Firstly, it had screws rather than being held together with plastic clips.  A bit of a result for me as it meant I could easily take it apart without fear of breaking the housing.

The base metal stopper was the same but the plastic stopper was on one of the cogs rather than being on the casing.  Again, fairly easy to take into account.

I then had to disconnect the little PCB and wire in the 2 resistors.  This is where I found out I'm a bit ham fisted and out of practice on the soldering.  I eventually got it done and re-assembled the servo.  It's a really tight fit in there but the screws made it easier to 'squeeze' it all back in.
I didn't have 2 x 2.2k Ohm resistors so I used 2. 1.5k Ohm resistors.  No idea what difference it makes but it worked.  If somebody can explain the affect I would really appreciate it.

Then it was down to attaching it to the Arduino.

I chose Pin10 for no other reason than I used it before to control a Servo.

As per the Maker guide I had to find the centre value.  For this servo it was 77.  If you do this your will probably be different..

I attached the servo.
Brown - Ground
Red - 5V
Orange - Analog in

It started rotating so I knew the mechanical bit worked.

The code below for the Arduino is quite simple as it was just for a test. 

// Servo Continuous
// Code to spin a servo modified to do continuous rotation
// Small cheap 9g servo modified using 2 x 1.5k Resistors
// and details from: http://makeprojects.com/Wiki/Servos

#include <Servo.h>

int CStop = 77;  // The value where the Servo is Stopped

Servo myservo10;  // create servo object to control a servo on pin10

void setup()
myservo10.attach(10);  // attaches the servo on pin 10 to the servo object
pinMode(13, OUTPUT);   // Using the LED on the Arduino UNO to know what is going on - not reallt needed 

void loop()
    // STOP - Setting to CStop stops the Servo
  myservo10.write(CStop); // Put servo stop
  digitalWrite(13, HIGH);   // set the LED on

  // Pause

  myservo10.write(5); // Rotate servo CLOCKWISE
  digitalWrite(13, LOW);   // set the LED on
  // Pause

    // STOP - Setting to CStop stops the Servo
  myservo10.write(CStop); // Put servo stop
  digitalWrite(13, HIGH);   // set the LED on

  myservo10.write(150); // Rotate servo ANTI-CLOCKWISE
  digitalWrite(13, HIGH);   // set the LED on
  // Pause

Video showing it rotating - yeah...

 My real aim is to use at least 2 of these to drive a vehicle of some sort.  Maybe use the PS2 controller to control it.  Or try to create a line following robot (not really a robot but that's appears to be what people call them)

I promise next time I will take pictures of the process for modifying the servo so that you can see what it looks like.

As a guide to do this first one it took me over an hour to get it done.  As I said a bit rusty...

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.