How To Connect A Linear Actuator To The Arduino (Part 2)

It’s been awhile since I last talked about Actuonix’s linear actuator, but I recently heard from some university students asking for commented source code. Unfortunately, the only comments I had regarding the source code were along the line of “Comments? We don’t need no steenking comments”.

Then I dug into the code and realized I DID need comments.

Oops.

Oh well…

So if you’re trying to get that actuator (or any actuator going) here’s some tips from when I was programming it for the Arduino:

  • Make sure you have enough current for the device. I can’t emphasize this enough. Motors use a LOT of current when they start up, and they’ll take it from the Arduino if necessary, effectively powering it down. The worst part is that it won’t be obvious or regular; instead, it will seem that the actuator is just acting up randomly, sometimes working and sometimes not. I’d recommend separate power supplies for the actuator and the Arduino, or if you have to share, a capacitor to isolate the ripples as the device starts up.
  • Ensure your actuator works like my code expects. The one I used works like a servo – give it a specific signal and it will try to go to a specific position. Like a servo, it relies on an on/off signal with the”on” part giving the position. To keep the position, the pulses have to be sent regularly; say 50 times a second or so, although I find most servos just stick to their last position if you interrupt the pulse train. With a typical servo, an “on” pulse for 1.5ms will be the 90 degree position, or center, or in the case of the actuator, about half way out.
  • Figure out the conversion. Translating degrees to inches is annoying. In the case of this device, it’s easier (and more accurate) to send the pulses in microseconds, which make more sense than degrees. I found a pulse ranging from 1,000 to 2,000usec (1.0 to 2.0 millisecond) moved the device from low to high. So you can use those values as a percent entry – 0% is 1,000usec and 100% is 2,000usec (the original function SetStrokePerc() did this, with a percent value from 1 to 99, to avoid edges problems with 0 and 100.) But what if you wanted to do it by measuring; say, 15mm high on a 50mm actuator? Then you’d want a percentage of 15/50=30%, or you could use the function SetStrokeMM(15,50) which just does the math for you.
  • Figure out the input. The servo functions will run and run and run, sending its signal – but unless you change the values, the actuator will never move. So you need to read data in, decide how to convert it, and then send it to the servo via myServo.writeMicroseconds() (or use the helper functions in the code.) One warning though – try not to change the values too quickly. The actuator is a physical device, and it simply won’t move from end to end in 1/10th of a second.
  • Understand the hardware. To use the servo code, you need to include it in your Arduino program, and connect it to a specific pin (the servo signal pin, NOT the power/ground pins) via a pin you specify in setup() with myServo.attach(pin#). I like to break the problem into two parts: hardware versus software. Start by using one of the demo servo programs in the Arduino to ensure your servo is working, then add your own code (or even modify the demo code in tiny pieces, saving your work frequently.) Alternately, you could use an ordinary servo, if you have one lying around, along with the demo program to eliminate any problems: If you get the demo working with a known working servo, then you know the Arduino is working. Swap in the actuator, and when you know it’s working, swap in the code. And so on.

These tips helped me get it up and running, and hopefully they’ll help you if you are using the actuator. Divide and conquer is always a smart practice when working with hardware, along with incremental additions; once you get one section working, just add bits at a time. Eventually, you’re on your way!

One thought on “How To Connect A Linear Actuator To The Arduino (Part 2)

  1. Hello, I’m working on a project using the Actuonix PQ12-R linear actuator, which is controlled exactly the same with normal RC servo. The problem is I don’t know if there are any method to combine an external controller (such as PID, Fuzzy) for more position accuracy of RC servo, because as I know this servo doesn’t have feedback signal. Thank you very much.