Using a servo to pull a cord - how complicated does the code need to be?

I'm looking to use a servo to pull on a cord. The cord is attached to a bell.

I have two questions:-

  1. Given that the servo can't "spin", and can only move 180deg max, I'll need to find a way to increase the travel...any tips?

  2. Code to drives servos seems fiendishly long and complicated. I was hoping there would be a function that would make interfacing with the library nice and tidy and simple...does anyone know of one? Essentially I am just looking for a nice bit of code to "sweep" the servo back and forth once without using delay. I've found the below.

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo, max = 8 servos int myservo_pin = 9; // pin that controls the servo int myservo_speed = 5; // how fast the servo moves, 1 = very fast, 10 = very slow long myservo_movetime = 0; // next time in millis servo next moves int myservo_gPos = 0; // target position to move towards int myservo_cPos = 0; // current postion of servo
 
int pos = 0;    // variable to store the servo position int cPos;       // current position int gPos;       // goal position int tDelay = 5; // delay between moves, gives appearance of smooth motion
 
void setup() {
  myservo.attach(X);  // attaches the servo on pin 9 to the servo object
    Serial.println("setup complete : smooth servo movment without delay v1"); } 
 
void loop() {
  cPos = myservo.read();
  if (cPos == 0) gPos = 180;
  if (cPos == 180) gPos = 0;
  if (cPos != gPos && millis() >= myservo_movetime) {
    moveServo();
  }
  if (Serial.available() > 0) { GetCommand(); } } 

void moveServo() {
  if (cPos < gPos) myservo.write(cPos+1);
  if (cPos > gPos) myservo.write(cPos-1);
  //if (cPos == gPos) // nothing
  myservo_movetime = millis() + tDelay;
}

void GetCommand() {
  int command = Serial.read() - '0';
  int mVal = command;
  if (mVal == 'x') {
    tDelay = tDelay * 10;
  } else {
    tDelay = mVal;
  }
  Serial.print("Pauses changed to : "); Serial.print(tDelay); Serial.println(" mSeconds");
  Serial.flush();
}

Servos try to get to their target position immediately. If you want a steady sweep you have to repeatedly tell it a new position.

MarkT:
Servos try to get to their target position immediately. If you want a steady sweep you have to repeatedly tell it a new position.

This is good news, MarkT. I don't want a steady sweep. For ringing on this bell cord, I almost need the servo to jerk! Good work.

Now to somehow extend the travel.

To extend the effective travel you can extend the servo arm. As long as you keep it within reason you won't overload the servo. The other option is to look for a continuous rotation servo, but then returning to a position is a problem.

An extended arm will produce a non-linear response to the servo rotation (in fact it's a sine function) you could use a capstan cylinder mounted onto the servo shaft. This will then produce a linear movement with respect to servo rotation. Assuming the servo offers 270 degrees of rotation (3/4 of a circle) a drum of diameter D will provide a pull movement X = 3.142 x .75 x D So if you have determined how much movement X you want, the drum diameter D needs to be X / (3.142 x .75)

To prevent overload of the servo if the rotation tries to exceed the permitted movement of the bell cord you can use a spring in the pull cord.

An image linked above shows a capstan with spring in the cord I made for a remote controlled camera

extended arm ==> some contra weight?

jackrae:
An extended arm will produce a non-linear response to the servo rotation (in fact it's a sine function) you could use a capstan cylinder mounted onto the servo shaft. This will then produce a linear movement with respect to servo rotation. Assuming the servo offers 270 degrees of rotation (3/4 of a circle) a drum of diameter D will provide a pull movement X = 3.142 x .75 x D So if you have determined how much movement X you want, the drum diameter D needs to be X / (3.142 x .75)

To prevent overload of the servo if the rotation tries to exceed the permitted movement of the bell cord you can use a spring in the pull cord.

IMG 0692 — Postimages

An image linked above shows a capstan with spring in the cord I made for a remote controlled camera

This I like. Thanks! Now to find a supplier of mini capstans.

  1. Given that the servo can't "spin", and can only move 180deg max, I'll need to find a way to increase the travel...any tips?

Sail winch servos are made for winding cord and make several turns.

For ringing on this bell cord, I almost need the servo to jerk! Now to somehow extend the travel.

Servo code can be as simple as below.

//zoomkat servo button test 7-30-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

wouldnt it be a lot easier to just use a solenoid? that will give you a 'jerky' movement on your chord and you could use and arm/pivot setup to increase the travel. then all you're dealing with is a relay and a digital output

scott_fx:
wouldnt it be a lot easier to just use a solenoid? that will give you a 'jerky' movement on your chord and you could use and arm/pivot setup to increase the travel. then all you're dealing with is a relay and a digital output

Something like this? That should work with the Arduino, right?

So I guess it would need to normally be "thrown" and then when activated "not thrown" to tug on the bell cord... Won't that constantly be drawing current?

I'll let the more informed members comment about if the arduino can power it or if you need a relay and external power supply. but, yeah that is the type of thing you can use. depending on the amount of force you need you can go larger too.

it'll only draw current in one state. while it's at rest it draws no current.

Probably a lot of interesting ways to use a standard servo to pull back a bell clapper and then release it to strike the bell.