ESP8266 - Actuator
This tutorial instructs you how to use ESP8266 to control Linear Actuator. In detail, we will learn:
- How a linear actuator works
- How to program ESP8266 to make a linear actuator extend or retract
- How to program ESP8266 to control the speed of a linear actuator

There are two types of linear actuators:
- Linear actuators without feedback: They are typically used to move to the furthest point and cannot be controlled to stop at a specific position.
- Linear actuators with feedback: They can be controlled to move to a specific position because they have a feedback signal.
This tutorial is for linear actuator without feedback. If you are interested in learning about linear actuator with feedback, please refer to the ESP8266 - Actuator with Feedback tutorial.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Linear Actuator

Linear Actuator Pinout
A Linear Actuator has two wires:
- The positive wire is usually red.
- The negative wire is usually black.

How It Works
When purchasing a linear actuator, it is essential to be aware of the voltage that it requires to operate. For instance, let's consider a 12V linear actuator.
When you power the 12V linear actuator by a 12V power source:
- Connect 12V and GND to the positive wire and negative wire, respectively: the linear actuator will extend at full speed until it reaches the limit.
- Connect 12V and GND to the negative wire and positive wire, respectively: the linear actuator will retract at full speed until it reaches the limit.
If the power to the actuator is cut off, the extension or retraction process will cease.
※ NOTE THAT:
For DC motor, servo motor, and stepper motor without gearing, when a load is present, if power is cut, they will not maintain their position. In contrast, an actuator can retain its position even when power is removed while carrying a load.
If the voltage of the power supply for linear actuators is less than 12V, the linear actuator will still extend/retract, but not at its maximum speed. This means that changing the voltage of the power source can affect the speed of the linear actuator. However, this approach is not commonly used due to the difficulty in controlling the voltage of the power source. Therefore, the voltage of the power source is kept constant, and the speed of the linear actuator is regulated by a PWM signal. The higher the duty cycle of the PWM, the faster the linear actuator extends/retracts.

How to control a linear actuator using ESP8266
Managing a linear actuator involves:
- Extending the linear actuator at its maximum rate.
- Retracting the linear actuator at its maximum rate.
- (Optional) Adjusting the speed of extending and retracting.
ESP8266 is able to generate a signal that can be used to control a linear actuator, however, the voltage and current of this signal is too low to be used as is. Therefore, a hardware driver must be used to bridge the gap between ESP8266 and the linear actuator. The driver has two functions:
- Amplify the control signal from ESP8266 (regarding both voltage and current)
- Receive another control signal from ESP8266 to switch the polarity of the power supply, thus allowing for direction control.
※ NOTE THAT:
- This tutorial can be used for all linear actuators, with 12V linear actuator being just an example.
- When controlling a 5V linear actuator, you still need a driver between the ESP8266 and the linear actuator. The ESP8266 pin gives only 3.3V and a tiny current, far too little for the linear actuator.
There are numerous types of chips and module available for linear actuator drivers. For this tutorial, we will be using the BTS7960 driver. A linear actuator draws a high current at the start of each move and when it pushes against its end stop, and the BTS7960 handles that easily.
Overview of BTS7960 Driver
The BTS7960 Driver (also sold as IBT-2) is a strong H-bridge module for one motor. This tutorial instructs you how to use it to regulate the linear actuator. Inside are two BTS7960B half-bridge chips under one big heat sink. Its motor side accepts 5.5V to 27V, and it can deliver up to 43A for a short time. It also wastes almost no voltage, while the L298N that this page used before lost about 2V.
BTS7960 Driver Pinout

The BTS7960 Driver has one channel, so it controls one linear actuator. It has an 8-pin header for the control signals and four screw terminals for the power wires.
The power pins:
- B+ and B- terminals: These terminals take the power for the linear actuator, here 12V from the power adapter.
- VCC pin: This pin powers only the small 74HC244 logic chip on the module. It needs 5V, which comes from the VIN pin of the NodeMCU when the board runs on USB.
- GND pin: This is a ground pin that must be connected to the GND of the ESP8266. On the module, it is joined to B-.
The control pins:
- RPWM pin: PWM here pushes the rod out (extend), and the duty cycle sets the speed.
- LPWM pin: A PWM signal on this pin makes the linear actuator retract.
- R_EN & L_EN pins: the two half-bridges work only while these enable pins are HIGH. LOW switches them off.
- R_IS & L_IS pins: These pins report the current. We do not use them, so they stay unconnected.
The output pins:
- M+ & M- terminals: are connected to the two wires of the linear actuator.
The control inputs accept signals from 3.3V to 5V, so the ESP8266 pins can drive them directly. The inputs have pull-down resistors, so no 5V goes back into the NodeMCU.
We can control one linear actuator with the help of an ESP8266 and a BTS7960 Driver. Four pins from ESP8266 are required: two PWM pins and two enable pins.
How To Control Linear Actuator
We will be studying the technique of managing a Linear Actuator with the help of a BTS7960 driver.
Wiring Diagram
Six jumper wires go straight from the NodeMCU to the header of the BTS7960. The actuator and the 12V adapter go into the screw terminals of the module.

This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
| BTS7960 Pin | Connect To |
|---|---|
| RPWM | ESP8266 D8 (GPIO15) |
| LPWM | ESP8266 D7 (GPIO13) |
| R_EN | ESP8266 D5 (GPIO14) |
| L_EN | ESP8266 D6 (GPIO12) |
| VCC | ESP8266 VIN (5V from USB) |
| GND | ESP8266 GND |
| B+, B- | (+) and (-) of the 12V power adapter, via the DC power jack |
| M+, M- | the two wires of the linear actuator |
| R_IS, L_IS | not connected |
D8 (GPIO15) must be LOW when the ESP8266 boots. The NodeMCU pulls it LOW, and the pull-down resistor inside the BTS7960 input keeps it LOW, so the board starts up normally.
How To Make Linear Actuator Expand/Retract
The ESP8266 must first drive both enable pins (R_EN and L_EN) HIGH. Then the Linear Actuator's moving direction is managed by the RPWM and LPWM pins. The table below shows how.
| RPWM pin | LPWM pin | Direction |
|---|---|---|
| 0 | 0 | Linear Actuator stops (brake) |
| PWM (1 to 255) | 0 | Linear Actuator extends |
| 0 | PWM (1 to 255) | Linear Actuator retracts |
Never put a PWM signal on RPWM and LPWM at the same time.
- Extends Linear Actuator.
- Retracts the Linear Actuator
※ NOTE THAT:
The orientation of the linear actuator can be changed by connecting its two wires to M+ & M- in a different order. To do this, it is necessary to either switch the wires on M+ & M- or swap the roles of RPWM and LPWM in the code.
How To Stop Linear Actuator from Extending or Retracting
The linear actuator will cease extending/retracting when it reaches the limit. Additionally, we can program it to stop extending/retracting before it reaches the limit.
There are two methods to halt a linear actuator:
- The driver brakes the actuator when both PWM pins drop to 0 and R_EN and L_EN are still HIGH.
- Or let the actuator coast: R_EN and L_EN go LOW, the outputs turn off, and it rolls to a stop.
How To Control the Speed of Linear Actuator via BTS7960 Driver
It is easy to regulate the speed of the linear actuator. To slow it down, give RPWM or LPWM a number below 255 rather than the full 255. This can be done by:
- Choosing two ESP8266 pins that support PWM and wiring them to RPWM and LPWM
- Making PWM with the analogWrite() function, on RPWM to push the rod out or on LPWM to pull it in. The BTS7960 Driver makes the weak 3.3V signal of the ESP8266 strong enough for the linear actuator.
The speed is a value ranging from 0 to 255. When the speed is 0, the linear actuator will come to a halt. At a speed of 255, the linear actuator will extend/retract at its maximum velocity. The code calls analogWriteRange(255) in setup(), because old ESP8266 cores used 0 to 1023 instead.
ESP8266 Example Code
The code below:
- Turns the BTS7960 driver on
- Extends the linear actuator at its maximum speed, until it stops at the limit
- Retracts the linear actuator at its maximum speed, until it stops at the other limit
- Repeats these two moves, 20 seconds each
Detailed Instructions
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram. Leave the 12V adapter unplugged for now.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
Copy the code above and open it in the Arduino IDE.
Click the Upload button on the Arduino IDE to upload the code to the ESP8266.
Plug in the 12V adapter to power the linear actuator.
You will observe:
- The linear actuator will extend until it reaches the limit, then it will stop.
- The linear actuator will remain in that position for a certain amount of time.
- The linear actuator will retract until it reaches the limit, then it will stop.
- The linear actuator will stay in that position for a certain amount of time.
- This process will be repeated continuously.