Linear Actuator with 10k feedback (to be used as a servo) I need sketch help Plz

Hello, I am trying to make a 12v linear actuator move as a hobby servo with an adjustable PID loop. The linear actuators have 10k slide potentiometers to measure position. I have experience in C++ programing, I have bought a copy of “Motors for Makers,” I still do not know enough to write the sketch. I have spent a decent amount of time looking for sketches, but I only find people running small hobby servos. I downloaded the Arduino compiler program, and read the forum rules. I need to take hobby servo PWM as input (from Frsky 8xr RX), then based on my position error a PID loop being run on the Arduino gives me power smoothly to desired position of the linear actuator. I have a powerful set of H-bridges to run the actuator, but I need the input signal to those H-bridges generated by the Arduino. Any help would be greatly appreciated, thank you! I need a sketch that I can tweak the PID for smooth servo performance. This will allow me to plug the Arduino into a RX receiver, and run the linear actuators as large servos.

thanks a million


Hi and welcome,

if you read the forum rules you might have noticed that you won’t get ready made solutions fitting your exact requirements. Rather than that it is expected that you come with own approaches and with distinct questions when you have run into a problem with coding.

Or, at the very beginning of a project (your case) some instructions/suggestions how to start and what to consider.

Unfortunately due to my lack of experience with servos I can only point you to this link, which might get you the right starting point.

How do you eat an elephant? One small piece at a time.

You need to approach your learning in the same way. Don't start with a program that tries to do everything. Start with several small programs that each do one thing - for example

  • decipher the PWM signal
  • move the actuator back and forth
  • get values from a potentiometer.

You may find some ideas in Planning and Implementing a Program


Since you'll need to have your servo loop running continually, you cannot use pulseIn() to read the
PWM signal - you'll need an interrupt routine to catch both rising and falling edges and record the
pulse width in a volatile variable (ie the result of micros() is sampled at rising and falling edges and
the difference is updated on each falling edge for the rest of the code to use.

The PID gets run with the error between actual and desired position, so convert the pulse width
into position terms, subtract the actual position (as calculated from analogRead).

The output of the PID is a signed quantity that controls the H-bridge, so you'll have to convert
a single signed quantity into direction + drive level.

Thank you for the advice and your time. I will post back with my small simple steps shown, but I feel like I will need some help on the start up and main loop. Any other advice on particular commands that will not work in my particular situation, I could use all the help I can get. Thanks