How to measure distance moved using a linear actuator

Hi there,

At the moment i’m involved in a little project with a mate of mine and hes attempting to build a device to measure the young modulus of materials. He’s using a load cell and an actuator in an attempt to calculate F/A and Delta(L)/original(L). We’re both new to arduino.

The actuator hes gone for has position feedback (Linked below), however once hooked up and using the following code:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position

void setup()
{
  Serial.begin(9600);
  myservo.attach(3);
}
void loop()
{
  Serial.println(myservo.read());
  for (pos = 0; pos <= 180; pos += 1)   // goes from 0 degrees to 180 degrees
  {
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    Serial.println(pos);
    delay(100);                       // waits 100ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1)   // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    Serial.println(pos);
    delay(100);                       // waits 100ms for the servo to reach the position
  }
}

The serial monitor displays numbers ranging from 0-179, not following the distance actually moved by the actuator. What i mean is where the actuator should be at full extension (180 degrees) the serial monitor reads 35, similarly when the actuator is at mid extension the serial monitor reads (130).

Is there a better way to measure the distance moved? Say I wanted the actuator to start at full extention (100mm) and it were to stop at value 40mm for example.

Link to actuator:

Many thanks

If you are using the Servo library then you aren't going to get any feedback. You just send out a command and you get no response from the servo. The Arduino has no way to tell if it is plugged in, much less if it arrived at the commanded destination.

That is a 3-wire servo actuator. You need one with 5 wires to get feedback.

If you keep using that actuator, look at using the Servo.writeMicroseconds() method.

orenziza:
Hi,

Thanks for your response. How might the Servo.writeMicroseconds() method resolve this issue?

The great thing about Arduino is, it's very easy to try it, and see if it helps

Look. Open the documentation online. See what it says about that method.

The first sentence in my reply still stands.

MorganS:
If you are using the Servo library then you aren't going to get any feedback.