Get free delivery on all orders over £20!

How to Control a 12V Linear Actuator with Arduino

How to Control a 12V Linear Actuator with Arduino

A linear actuator converts rotary motor motion into straight-line movement, which makes it useful for pushing, lifting, tilting and opening things in robotics, home automation and DIY projects. In this guide you will learn how to control a 12V linear actuator with an Arduino, including the wiring, the parts you need, and simple code to extend and retract it.

What you will need

Step 1: Understand the actuator

A 12V linear actuator has two wires. Applying 12V in one polarity extends the rod; reversing the polarity retracts it. It draws more current than an Arduino pin can supply, so you must never power it directly from the Arduino's 5V pin. You need a driver in between.

Two common options:

  1. Motor driver (BTS7960) — lets you reverse direction and control speed with PWM. Best for most projects.
  2. Relay module — simple on/off control, direction set by wiring. Fine for slow, fixed-speed moves.

Step 2: Wiring with the BTS7960 motor driver

BTS7960 pin Connect to
VCC Arduino 5V
GND Arduino GND
R_EN Arduino pin 4
L_EN Arduino pin 5
R_PWM Arduino pin 6
L_PWM Arduino pin 7
B+ (VMS) 12V power supply positive
B- (GND) 12V power supply negative
MOTOR_A Actuator wire 1
MOTOR_B Actuator wire 2

Make sure the 12V supply is rated for the actuator's stall current. Do not run the actuator past its end stops under load for long periods.

Step 3: Upload the code

This example extends the actuator for 3 seconds, pauses, retracts for 3 seconds, then stops.

#define R_EN 4
#define L_EN 5
#define R_PWM 6
#define L_PWM 7

void setup() {
  pinMode(R_EN, OUTPUT);
  pinMode(L_EN, OUTPUT);
  pinMode(R_PWM, OUTPUT);
  pinMode(L_PWM, OUTPUT);
  Serial.begin(9600);
  Serial.println("Linear actuator test");
}

void loop() {
  // Extend
  digitalWrite(R_EN, HIGH);
  digitalWrite(L_EN, LOW);
  analogWrite(R_PWM, 200);
  analogWrite(L_PWM, 0);
  delay(3000);

  // Stop
  digitalWrite(R_EN, LOW);
  digitalWrite(L_EN, LOW);
  analogWrite(R_PWM, 0);
  analogWrite(L_PWM, 0);
  delay(2000);

  // Retract
  digitalWrite(R_EN, LOW);
  digitalWrite(L_EN, HIGH);
  analogWrite(R_PWM, 0);
  analogWrite(L_PWM, 200);
  delay(3000);

  // Stop
  digitalWrite(R_EN, LOW);
  digitalWrite(L_EN, LOW);
  analogWrite(R_PWM, 0);
  analogWrite(L_PWM, 0);
  delay(2000);
}

Adjust the delay values to your stroke length and speed so the actuator does not run past its limits.

Step 4: Test the setup

  1. Connect the Arduino to your computer with USB.
  2. In the Arduino IDE, select your board and port from the Tools menu.
  3. Upload the code.
  4. The actuator should extend, pause, retract and pause in a loop.

Troubleshooting

  • Actuator does not move: check the 12V supply is connected and powered, and that the driver's B+ and B- are not reversed.
  • Actuator moves in the wrong direction: swap the two MOTOR_A/MOTOR_B wires.
  • Erratic movement: check all connections, especially the PWM pins and the common ground between Arduino and driver.
  • Motor stalls: the load may exceed the actuator's rated force for the speed you chose; pick a slower speed or higher-force variant.

Applications of a 12V linear actuator

  • Automatic window or vent openers
  • Desk height adjustment and lifting platforms
  • Robot arms and grippers
  • Camera tilt and pan mechanisms
  • Automated pet feeders and door latches

If you are building one of these projects, the 12V Micro Linear Actuator is available in 10 mm, 15 mm, 20 mm and 25 mm strokes and speeds from 4 mm/s to 30 mm/s. Pair it with a BTS7960 motor driver and an Arduino board to get started.

Notice an Issue? Have a Suggestion?
If you encounter a problem or have an idea for a new feature, let us know! Report a problem or request a feature here.

Leave a comment