ESP32 UNO - Actuator
Need a rod that pushes and pulls on command? Drive a 12V linear actuator with the ESP32 Uno and a BTS7960 motor driver, using four signal wires. The ESP32 Uno form board decides the direction, and a PWM signal sets how fast the rod travels. It is a solid base for DIY automation, such as a lid opener or a lifting table.
By the end, you can:
- Explain how a linear actuator turns motor spin into straight motion
- Wire a BTS7960 driver between the board and a 12V actuator
- Push and pull the rod with the two PWM pins
- Halt the rod at any point of its stroke
- Set the rod speed with a PWM duty value

This page is for actuators with two wires and no position sensor. For a model with a feedback wire, go to ESP32 Uno - Actuator with Feedback.
Components You Need
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 .
Linear Actuator Basics
After this part, you know what moves inside the actuator and how to steer it.
A small DC motor and a lead screw sit inside the tube. The motor turns the screw, and the screw drives the rod forward or backward in a straight line.

Actuator Wires
There are just two leads on the actuator.
| Wire | Usual Color | Role |
|---|---|---|
| Positive | Red | Gets the supply for an outward move |
| Negative | Black | Gets the supply for an inward move |

Direction, Holding and Speed
Read the rated voltage on the label first. The example here uses a 12V model.
| Positive Wire | Negative Wire | Rod Movement |
|---|---|---|
| 12V | GND | Moves out at top speed until the outer end stop |
| GND | 12V | Moves in at top speed until the inner end stop |
| GND | GND | Stays still |
※ NOTE THAT:
Gearless DC, servo and stepper motors slip under a load once the power is cut. A linear actuator does not. Its screw locks the rod, so a weight stays where it is with zero power.
A lower supply, say 9V on a 12V unit, still moves the rod, only slower. Building an adjustable voltage source is awkward, though. The usual trick is a fixed 12V supply switched on and off very quickly by PWM. The bigger the duty cycle, the quicker the rod travels.

Driving a Linear Actuator from the ESP32 Uno
Typical jobs for the actuator are:
- Push out at full speed
- Pull in at full speed
- Optional: move at a reduced speed
Good to know: an ESP32 Uno GPIO outputs 3.3V and only a few milliamps. That cannot turn the motor, so a driver goes in the middle.
| Driver Job | Result |
|---|---|
| Amplify the weak GPIO signal | The motor gets the full 12V and enough current |
| Flip the supply polarity on command | The rod changes direction |
※ NOTE THAT:
These steps fit any linear actuator; 12V is just the sample here. A 5V actuator also needs a driver, since one ESP32 Uno pin cannot deliver the current a motor draws. Never wire a motor lead to a GPIO.
Here the BTS7960 does the job. Chips like the L293D, or other driver boards, also work for small actuators.
BTS7960 Motor Driver Basics
After this part, you can name every pin on the BTS7960 board.
The BTS7960 (often sold as IBT-2) is one big H-bridge built from two BTS7960B half-bridge chips on a heat sink. It drives one motor or one actuator in both directions. The rod pulls a surge of current when it starts and when it jams against an end stop, and the BTS7960 handles that easily; the L298N it replaces dropped about 2V and ran out of current there.
BTS7960 Driver Pinout

The board has an 8-pin control header and a 4-way screw terminal. One board moves one actuator.
Power Terminals
| Terminal | Role |
|---|---|
| B+ and B- | Motor supply, 5.5V to 27V (12V adapter here) |
| M+ and M- | Outputs to the actuator wires |
Control Header
| Pin | Role |
|---|---|
| RPWM | PWM here pushes the rod out; the duty cycle sets the speed |
| LPWM | PWM here pulls the rod in |
| R_EN and L_EN | Turn the two half-bridges on (HIGH) or off (LOW) |
| R_IS and L_IS | Current sense outputs, left free here |
| VCC | 5V for the module's 74HC244 buffer chip; feed it from the ESP32 Uno 5V pin |
| GND | Common ground (0V), joined to B- on the module |
Limits and Logic Level
The chips handle up to 43A at peak, which is far more than a hobby actuator needs. The control inputs accept 3.3V to 5V, so the ESP32 Uno drives them as they are. They also have pull-down resistors, so no 5V flows back into a GPIO.
Each actuator uses four ESP32 Uno pins: two PWM pins and two enable pins.
※ NOTE THAT:
Only one actuator is used below. A second actuator needs its own BTS7960 and four more pins, wired the same way.
ESP32 Uno Pinout
Your code uses the GPIO number that sits behind each Uno header label. Find D9, D11, D12 and D13 in this diagram before you plug in any jumper wire.

Moving the Linear Actuator
By the end of this part, the hardware is connected and you know the code lines for each move.
How to Connect
Keep the 12V adapter out of the DC jack while you wire. Then connect the parts as in the picture.

This image is created using Fritzing. Click to enlarge image
| BTS7960 Pin | ESP32 Uno Pin |
|---|---|
| RPWM | D9 (GPIO13) |
| LPWM | D11 (GPIO23) |
| R_EN | D13 (GPIO18) |
| L_EN | D12 (GPIO19) |
| VCC | 5V |
| GND | GND |
| R_IS, L_IS | not connected |
| Other Wire | Goes To |
|---|---|
| Actuator positive and negative | M+ and M- |
| 12V adapter + | BTS7960 B+ |
| 12V adapter - | BTS7960 B- |
The female headers grip thin jumper wires only loosely. For a build that has to last, stack a Screw Shield V2 or a Proto Screw Terminal Block Shield on the ESP32 Uno and clamp each wire in its terminal. Nothing else changes:

This image is created using Fritzing. Click to enlarge image
Good to know: LPWM sits on D11, not D10. D10 is GPIO5, a boot strapping pin, so it is left free. The four control lines only leave the ESP32 Uno, and the BTS7960 accepts 3.3V as HIGH. No level shifter is needed, and no 5V signal ever enters a board pin.
Push Out and Pull In
With R_EN and L_EN both HIGH, the two PWM pins pick the direction.
| RPWM Value | LPWM Value | Rod of the Actuator |
|---|---|---|
| PWM | 0 | Travels out |
| 0 | PWM | Travels in |
| 0 | 0 | Halted (brake) |
Never send PWM to both pins at once. One of them must be 0.
Push the rod out
Pull the rod in
※ NOTE THAT:
Rod going backward? The leads on M+ and M- are reversed. Swap those two leads, or swap RPWM and LPWM in the sketch.
Halting the Rod Mid-Stroke
The actuator cuts out by itself at each end. To stop it somewhere in between, use one of these options.
| Method | Code |
|---|---|
| Brake (both PWM at 0) | analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); |
| Driver off (both enables LOW) | digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW); |
Option 1 — brake
Option 2 — driver off
Set R_EN and L_EN back to HIGH before the next move.
Speed Control with PWM on RPWM and LPWM
A PWM value below 255 on the active pin slows the rod down.
- Keep RPWM on D9 (GPIO13) and LPWM on D11 (GPIO23).
- Send the duty value with analogWrite() to RPWM (out) or LPWM (in). The BTS7960 switches the 12V with the same pulses.
| speed Value | Rod Behavior |
|---|---|
| 0 | Halted |
| 100 | Slow travel |
| 180 | Medium travel |
| 255 | Top speed |
Good to know: analogWrite() works on the ESP32 Uno with the familiar 0–255 range, so speed code from other Arduino boards runs as-is. Very low values may not overcome the screw friction, so the rod may not move at all.
ESP32 Uno Example Code
The sketch runs a full-speed cycle: out, wait, in, wait, and again.
Upload and Test
- First time with this board? Set it up with ESP32 Uno - Getting Started before you continue.
- Keep the 12V adapter unplugged for now.
- Build the circuit by following the wiring table above.
- Plug in the USB Type-C cable between the ESP32 Uno and your computer.
- Select the board in Arduino IDE: pick ESP32 Dev Module and the COM port of the board (CH340).
- Paste the sketch into a new Arduino IDE window.
- Click Upload and wait for "Done uploading".
- Connect the 12V adapter to the DC jack. Check this sequence:
- The rod travels out and halts at its outer end stop
- It holds there for the rest of the 20 seconds
- It travels back in and halts at its inner end stop
- It holds again, and the loop restarts
Video Tutorial
See the ESP32 Uno build in action in the video below.
How the Code Works
| Code Part | What It Does |
|---|---|
| #define RPWM_PIN 13 / LPWM_PIN 23 | D9 (GPIO13) and D11 (GPIO23) carry the PWM for out and in |
| #define R_EN_PIN 18 / L_EN_PIN 19 | D13 (GPIO18) and D12 (GPIO19) switch the driver on |
| R_EN and L_EN HIGH in setup() | Turns the driver on for the whole run |
| RPWM 255 and LPWM 0, then delay(20000) | Rod moves out at top speed for up to 20 seconds |
| RPWM 0 and LPWM 255, then delay(20000) | Rod moves in at top speed for up to 20 seconds |
The end stops cut the motor before the 20 seconds pass, so the rod simply rests at each end until the next command.
ESP32 Uno vs UNO R4 for This Project
Moving this build from the UNO R4 to the ESP32 Uno changes some pin numbers and the board setup.
| Item | Arduino UNO R4 | ESP32 Uno |
|---|---|---|
| Logic voltage | 5V | 3.3V |
| RPWM pin in code | 9 (D9) | 13 (D9) |
| LPWM pin in code | 10 (D10) | 23 (D11) |
| R_EN pin in code | 12 (D12) | 18 (D13) |
| L_EN pin in code | 11 (D11) | 19 (D12) |
| PWM range with analogWrite() | 0 to 255 | 0 to 255 |
| WiFi and Bluetooth | WiFi on the R4 WiFi only | WiFi plus Bluetooth Classic and BLE |
| Arduino IDE board | Arduino UNO R4 WiFi or Minima | ESP32 Dev Module |
On the ESP32 Uno, LPWM, L_EN and R_EN each move one header hole up, so that D10 (a boot strapping pin) stays free. The BTS7960 reads 3.3V as HIGH, and no signal travels back into the board, so no level shifter is needed.
Wrap-Up
You built a full actuator setup: BTS7960 wiring, out and in moves with the two PWM pins, two ways to halt the rod, and PWM speed control. The same method works for any actuator without feedback. Use it for a motorized hatch, a TV lift or a chicken coop door.
Go Wireless: Move the Rod from Your Phone
After this part, you know how to take the actuator off the USB cable and control it from a phone.
The ESP32 Uno has WiFi and Bluetooth built in. Put a slider on your phone screen and map its value to the RPWM or LPWM duty cycle, or use two buttons of a joystick for out and in. Then you can open a lid or raise a shelf from across the room.
Try These Next
- Use a speed of 120 for the outward move and 255 for the inward move.
- Add two buttons: one pushes the rod out while held, the other pulls it in.
- Stop the rod halfway by cutting the motor after half the stroke time.
- Add a second BTS7960 for a second actuator and move both rods at the same time.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port appears in Arduino IDE | CH340 driver not installed or a charge-only cable | Install the CH340 driver and use a USB cable that carries data |
| Upload stops at "Failed to connect" or "Waiting for download" | The chip did not enter download mode | Hold the BOOT button when the upload starts and let go once writing begins |
| Rod never moves | 12V adapter off, or R_EN / L_EN / VCC not wired | Plug in the adapter, check B+ and B-, confirm R_EN goes to D13, L_EN to D12 and VCC to 5V |
| Rod moves out but never comes back | LPWM wire loose or on the wrong header | Check that LPWM sits on D11 and the code uses 23 |
| Board reboots each time the rod starts | Grounds not shared, or the motor pulls power from USB | Wire the BTS7960 GND to the board GND, and power the motor only from the adapter |
| Rod crawls or stalls under load | Adapter too weak or PWM value too low | Use an adapter rated for the actuator current and raise the speed value |
| BTS7960 heat sink gets hot | The rod is pushed against an end stop or blocked for a long time | Let the end stops do their job, and give the module some airflow |
| Rod turns back before it reaches the end | The stroke takes longer than 20 seconds | Increase both delay() values |
FAQ
Why do I need the BTS7960 instead of wiring the actuator to a GPIO?
A GPIO gives 3.3V at a few milliamps, but an actuator motor pulls hundreds of milliamps or more. The motor also kicks back voltage spikes. A driver supplies the current and keeps those spikes away from the board.
Is 3.3V from the ESP32 Uno enough for the BTS7960 inputs?
Yes. The BTS7960 control inputs accept 3.3V to 5V, so the RPWM, LPWM, R_EN and L_EN lines work directly. All four lines are outputs, so no 5V reaches the board.
Why does VCC of the BTS7960 go to 5V on a 3.3V board?
VCC only powers the small buffer chip on the module, and its maker asks for 5V. It is not a signal line, so it never feeds 5V into a GPIO. The actuator gets its power from B+ and B-.
How much current does a 12V linear actuator draw?
Small hobby models draw around 1A under load and up to 2–3A when stalled at an end stop. Check the datasheet and pick a 12V adapter rated above the stall current.
Which other ESP32 Uno header pins can drive the BTS7960?
Most ESP32 Uno digital pins support PWM. Change the four GPIO numbers in the code. Avoid D8 (GPIO12) and D10 (GPIO5), because they are boot strapping pins, and avoid A2–A5 (GPIO35, 34, 36, 39), because they are input only and cannot drive the BTS7960.
Do I need a library to run a linear actuator on the ESP32 Uno?
No. The sketch only uses pinMode(), digitalWrite(), analogWrite() and delay(), which come with the esp32 by Espressif Systems core.
Can the ESP32 Uno know where the rod is?
Not with a two-wire actuator. You can only estimate the position from the time it has moved. For a real position reading, use an actuator with a feedback wire and read it on an analog pin.
Will a motor driver shield in Uno shape fit the ESP32 Uno?
The headers match the Uno layout, so many shields plug in. Check that the shield does not send 5V signals back into a board pin, and that it does not need AREF, because that spot is the Reset pin on this board.
What stops the rod at each end if the code keeps the motor on?
Each actuator has built-in limit switches. When the rod reaches an end, a switch cuts the motor current, even while the ESP32 Uno still sends the PWM signal. That is why the sketch can use a long delay safely.
What if my build needs extra pins beyond the Uno headers?
The ESP32 Uno has a few extra holes near the power header: GPIO32 and GPIO33 (I/O, PWM, analog on ADC1, so they also work while WiFi is on) and GPIO15 (I/O, PWM, analog on ADC2). Solder pin headers there and write the GPIO number in code. For the control lines of a second BTS7960, GPIO32 and GPIO33 are the first picks. Keep two warnings in mind. First, GPIO15 and GPIO0 (the IO0 pin at the unused Uno NC spot) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code, so use GPIO32/33 first. Second, never touch the six holes under the digital header (SD0–SD3, CMD, CLK = GPIO6–GPIO11); they are wired to the flash chip, and using them crashes the board.
Can I control the actuator over WiFi and still use the same pins?
Yes. D9, D11, D12 and D13 are plain digital and PWM outputs, so WiFi does not affect them. Only analog reads on the ADC2 pins stop working while WiFi is on.