Arduino UNO R4 - Actuator

Discover how to use the Arduino Uno R4 to control a linear actuator in this easy tutorial! Perfect for beginners, this guide shows you how to use a BTS7960 driver for fun DIY projects. Here’s what you’ll learn:

Arduino UNO R4 controls a 12V linear actuator with a BTS7960 motor driver

This tutorial is about linear actuators without feedback. If you want to learn about linear actuators with feedback, visit our Arduino UNO R4 - Actuator with Feedback guide. Follow this easy Arduino project to build your own smart automation system!

Overview of Linear Actuator

Linear Actuator Extend Retract

Linear Actuator Pinout

A linear actuator comes with two wires.

  • Positive wire: often red
  • Negative wire: often black
Linear Actuator Pinout

How It Works

When purchasing a linear actuator, it's important to understand which voltage it operates on. For instance, consider a linear actuator that uses 12 volts.

When you connect the 12V linear actuator to a 12V power supply:

  • Connect 12V to the positive wire and GND to the negative wire: the linear actuator extends fully at high speed until it stops at its limit.
  • Connect 12V to the negative wire and GND to the positive wire: the linear actuator retracts fully at high speed until it stops at its limit.

When you cut off the power to the actuator by connecting both the positive and negative wires to the ground, the actuator will stop moving in or out.

※ NOTE THAT:

For DC motors, servo motors, and stepper motors without gears, they cannot maintain their position when the power is turned off and they are carrying a load. However, an actuator can maintain its position even without power when it is carrying a load.

If we use less than 12V for linear actuators, they still work but not at their fastest speed. This shows that changing the power supply voltage can adjust the speed of the linear actuator. However, controlling the voltage precisely is difficult, so this method is not commonly used. Instead, the voltage is kept constant and the speed of the linear actuator is controlled using a PWM signal. When the PWM duty cycle is higher, the linear actuator moves faster.

How to control linear actuator

How to Control a Linear Actuator with Arduino Uno R4

To control a linear actuator, we usually want to:

  • Make it extend (move out) at full speed
  • Make it retract (move back in) at full speed
  • (Optional) Control how fast it moves in or out

The Arduino can send control signals, but these signals are too weak (low voltage and current) to move the actuator directly. That’s why we need a driver between the Arduino and the actuator.

The driver does two main jobs:

  • It boosts (amplifies) the Arduino’s signal so it can power the actuator.
  • It switches the power direction (by changing the polarity) based on another signal from the Arduino — this controls whether the actuator extends or retracts.

※ NOTE THAT:

  • You can use this guide for any linear actuator. We use a 12V linear actuator as an example.
  • When using a 5V linear actuator with an Arduino UNO R4, even though both use 5V, you need to add a driver. This is because the Arduino UNO R4 cannot supply enough current for the actuator.

This guide uses the BTS7960 driver. It is a strong driver, so it is a safe choice for a 12V actuator.

Overview of BTS7960 Driver

The BTS7960 module (also sold as IBT-2) can drive one big DC load in both directions. A linear actuator is a good example. In this tutorial, we use it to push the actuator out and pull it back in.

A linear actuator pulls a big current for a short time. This happens when it starts to move, and again when it hits its end stop. The BTS7960 handles up to 43A at peak, so these short current jumps do not hurt it. It also loses almost no voltage inside, so the actuator gets the full 12V. That is why it replaced the L298N on this page.

BTS7960 Driver Pinout

BTS7960 Motor Driver Pinout

The BTS7960 module has two parts: an 8-pin control header and a 4-way screw terminal block.

Control header pins:

  • RPWM pin: PWM input for one direction. In this guide, it makes the actuator extend.
  • LPWM pin: PWM input for the other direction. In this guide, it makes the actuator retract.
  • R_EN & L_EN pins: enable pins. Both must be HIGH to turn the driver on. When both are LOW, the outputs are off.
  • R_IS & L_IS pins: current sense outputs. We do not use them. Leave them unconnected.
  • VCC pin: 5V supply for the small logic chip on the module. Connect it to the 5V pin of the Arduino UNO R4.
  • GND pin: connect it to GND of the Arduino UNO R4.

Screw terminal pins:

  • B+ & B- pins: the power supply for the actuator, from 5.5V to 27V. We use a 12V power adapter.
  • M+ & M- pins: connect to the two wires of the linear actuator.

The control inputs accept 3.3V to 5V signals, so the Arduino UNO R4 pins can drive them directly. One BTS7960 module controls one linear actuator. For two actuators, use two modules.

※ NOTE THAT:

The actuator never takes power from the Arduino UNO R4. It takes power only from the 12V adapter on B+ and B-.

How To Control Linear Actuator

This part shows the steps to drive a linear actuator with a BTS7960 module and the Arduino UNO R4.

Wiring Diagram

Make all the wires first. Plug in the 12V adapter last.

The wiring diagram between Arduino UNO R4 Linear Actuator BTS7960 Driver

This image is created using Fritzing. Click to enlarge image

BTS7960 Pin Arduino UNO R4 Pin / Other Part
RPWM D9
LPWM D10
R_EN D12
L_EN D11
VCC 5V
GND GND
R_IS, L_IS not connected
B+ + of the 12V power adapter (through the DC power jack)
B- - of the 12V power adapter (through the DC power jack)
M+, M- the two wires of the linear actuator

An actuator often sits inside a moving machine, and a loose jumper wire can stop it in the middle of a stroke. For a firm hold, add a Proto Screw Terminal Block Shield or a Screw Shield V2 to the Arduino UNO R4 and screw each wire down. The wiring with the Screw Shield V2 looks like this:

The wiring diagram between Arduino UNO R4 Linear Actuator BTS7960 Driver Screw Shield

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Uno R4 and other components.

How To Make Linear Actuator Expand/Retract

The driver only works when R_EN and L_EN are both HIGH. After that, the PWM pin that gets the signal decides if the rod goes out or in. The table below shows how to do this.

RPWM pin LPWM pin Direction
0 0 Linear Actuator stops
255 0 Linear Actuator extends
0 255 Linear Actuator retracts
  • Lengthens the linear actuator
analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255);
  • The linear actuator retracts.
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 255);

Always set the other PWM pin to 0 first. RPWM and LPWM should never both receive a signal.

※ NOTE THAT:

If the M+ and M- pins are connected to the linear actuator incorrectly, the direction will be reversed. To fix this, simply switch the two actuator wires on M+ and M-, or swap RPWM_PIN and LPWM_PIN in the program.

How To Stop Linear Actuator from Extending or Retracting

The linear actuator stops moving out or back automatically when it gets to its maximum or minimum point. We can also set it to stop moving before it reaches these points.

There are two methods to halt a linear actuator.

  • Brake: set both PWM pins to 0 while R_EN and L_EN stay HIGH. The actuator stops right away.
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0);
  • Turn the driver off: set R_EN and L_EN to LOW. The outputs are cut, and the actuator stops by itself.
digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW);

How To Control the Speed of Linear Actuator via BTS7960 Driver

To change the speed, send a PWM value from 0 to 255 instead of 255. Here’s how you can do it:

  • On the Arduino UNO R4, the PWM pins carry a "~" mark. Use two of them for RPWM and LPWM.
  • Use the analogWrite() function on RPWM to extend, or on LPWM to retract. The BTS7960 driver turns this weak signal into a strong 12V signal for the actuator.
analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, speed); // extend, speed from 0 (0% on) to 255 (100% on)

The speed can be any number from 0 to 255. At speed 0, the linear actuator will stop. At speed 255, it moves at its fastest speed.

Arduino UNO R4 Example Code

This code performs the following tasks:

  • Move the actuator out as fast as possible
  • Stop the actuator
  • Move the actuator back in as fast as possible
  • Stop the actuator
/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-actuator */ #define RPWM_PIN 9 // The Arduino UNO R4 pin connected to the RPWM pin of the BTS7960 (extend) #define LPWM_PIN 10 // The Arduino UNO R4 pin connected to the LPWM pin of the BTS7960 (retract) #define R_EN_PIN 12 // The Arduino UNO R4 pin connected to the R_EN pin of the BTS7960 #define L_EN_PIN 11 // The Arduino UNO R4 pin connected to the L_EN pin of the BTS7960 void setup() { // initialize digital pins as outputs. pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // start with no PWM signal, then turn the driver on analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } // the loop function runs over and over again forever void loop() { // extend the actuator at full speed analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255); delay(20000); // actuator will stop extending automatically when reaching the limit // retract the actuator at full speed analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 255); delay(20000); // actuator will stop retracting automatically when reaching the limit }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Wire the components according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Paste the code into Arduino IDE.
  • Press the Upload button in Arduino IDE to transfer the code to Arduino UNO R4.
  • Plug the 12V adapter into the DC power jack.
  • Observe the following:
    • The linear actuator extends and stops upon reaching its limit.
    • The linear actuator holds its position for a period of time.
    • The linear actuator retracts and stops upon reaching its limit.
    • The linear actuator holds its position for a period of time.
    • This sequence repeats continuously.

    Want to know more about this driver? Read Arduino UNO R4 - BTS7960 Motor Driver.

Video Tutorial

Summary

In this Arduino UNO R4 tutorial, you learned how to control a linear actuator with a BTS7960 driver for DIY automation. This easy guide showed you how to make the actuator move in and out, wire the BTS7960 driver, and change its speed using Arduino programming. Focused on linear actuators without feedback, this simple Arduino project helps you build smart automation systems. Now you can use these skills to create your own motion control projects with Arduino UNO R4!

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!