How to control a linear actuator with an Arduino

Controlling a linear actuator is fun and easy. They’re really strong and can be used for all kinds of things: raising your TV out of a hidden pocket; crushing your enemies; or building an RC backhoe or dump truck. I did this entire project in about 20 minutes for around $150 CAD.

Linear Actuator Circuit Parts

Linear Actuator Circuit Assembly

The board comes with screw terminals and male/male headers unattached. I used my trusty Solomon SR-998 soldering iron to attach them. The board has four large holes for wires that are not the right spacing for the screw terminals. Immediately next to the large holes are pairs of smaller holes that work perfectly.

I then attached the rest of the components. Here’s a simplified circuit diagram.

Actuator circuit
Actuator circuit. Click for larger version.

The female power plug screwed into GND/VIN on the VNH5019 so I could unplug the power supply with ease. You could put switch in here for an E-stop.

The Arduino is powered from the USB connection. For this demo you have to have the USB and the 12v5a power connected. The Arduino can handle 12v so you could get a 12v6a power supply and power everything without a USB. I wanted to keep this simple, but feel free to discuss it in the forums.

Linear Actuator Code

I carefully read the VNH5019 instructions before I made my purchase. You’d do your homework too, right? Right. That’s how I knew what to put in the Arduino code.

Get the code here: https://github.com/MarginallyClever/vnh5019_linear_actuator/

Now you

Did this tutorial help you? Give us a shout on the forums and show your creation. We’d love to share it with the world.

Got questions? See something that could be better? Post below!

Only registered users can comment.

  1. How are you controlling the linear actuator? How would you control it remotely?
    Thank you

    1. take a look at the link to the code in the article. This could be changed to listen for commands from the serial line (sent from the PC). Another way would be to use a NodeMCU instead of an arduino, and then you could access it remotely over the internet.

  2. Could you explain how it could be controlled using a sensor i.e. when object is detected, it moves in one direction, and the reverse direction when there is no object.

    1. The arduino can turn on the power of the h bridge to drive the actuator in or out. The arduino could also listen to a sensor and when the sensor changes state (it detects something) the arduino could then decide what action to take (move actuator in, for example)

  3. Could you control the distance and force applied?

    Could it run out to a certain distance but if there is to much force in the way it would stop, then try again. Say as to change a gear in a gear box.

    1. Out of the box this actuator does not have a distance sensor or a force sensor. Both would need to be added to do what you ask.

  4. Hello Dan,

    I try your tutorial for the electrical actuator. it’s working for the forward, but not for the Backward.

    What happen ?

    I need your help on

    Regards

    1. post a video of your circuit to the forums and a link to your code. Then maybe I can see the problem.

      1. I am having this same issue, Im using a longer stroke actuator. It slowly moved forward but never back. I used the same wiring and code. I’m jus wondering what i will need to change the code to have this move a bit quicker and backwards in a loop.

        1. What controller are you using? Does the light change when the direction changes? (see video) My guess from no information given is that the direction is not being reversed.

  5. Thank you for ths tutorial, I am actually a student dping this as a project so excuse my lack of experience. My question is the following : How did you exactly attatch the male male header the arduino ? Is there a special wire used to connect the Arduino to the pins ? Were the long parts of the pins facing the ground when you inserted them before soldering ? Thank you very much.

    1. male male headers fit into the female headers on the Arduino. I don’t understand where you’re stuck.

  6. Hi Dan, can you please share the Polulu VNH5019 library you used for Arduino ?
    Thanks in advance.

  7. I have copied your same code and wired everything as you explained and the actuator only moves out. The light is green and red at the same time and then when it is extended fully, it just stays fading green on and off. I am also using a longer stroke actuator. Thanks.

    1. If your results differ, something has changed. Different model of board? Different wiring? Different pins on the Arduino?

  8. The code uses PIN 2, 3, 4, while in the circuit diagram you wrote 3, 4, 5.
    I was having the same issue as Sap and Kevin, I think that’s the reason they’re having it too!

    Fixed the wiring (or the code, your choice!) and everything worked!

    Just a note: the actuator goes more forward than backward so, after a while, I’ll the actuator fully extend. I’ll fix it in the code, no big deal!

    Thank you Dan!