ESP32 S3 UNO - Actuator

This ESP32 S3 Uno linear actuator tutorial shows you how to wire a 12V linear actuator to the ESP32 S3 Uno form board through an L298N driver and control it with Arduino code. You will make the actuator push out and pull back in, stop it at any point, and change its speed with PWM. It is a simple first step into DIY automation.

In this tutorial, you will:

  1. Learn what a linear actuator is and how it moves
  2. Wire an L298N driver and a linear actuator to the ESP32 S3 Uno
  3. Extend and retract the actuator with the IN1 and IN2 pins
  4. Stop the actuator before it reaches its end point
  5. Control the linear actuator speed with analogWrite()
ESP32 S3 Uno linear actuator

This page covers linear actuators without feedback. If your actuator has a position feedback wire, read the ESP32 S3 Uno - Actuator with Feedback guide instead.

Hardware Preparation

1×ESP32 S3 Uno-form Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Linear Actuator
1×L298N Motor Driver Module
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Linear Actuator

A linear actuator turns the rotation of a small motor into a straight push or pull. You see it in electric desks, window openers and solar trackers. Knowing how it moves makes the code much easier to follow.

Linear Actuator Extend Retract

Linear Actuator Pinout

The actuator has only two wires. The positive wire is often red, and the negative wire is often black.

Linear Actuator Pinout

How It Works

Every linear actuator has a rated voltage, so check it before you buy one. This guide uses a 12V actuator as an example.

Direction

If you connect 12V to the positive wire and GND to the negative wire, the actuator pushes out at full speed until it hits its end limit. If you swap the two wires, it pulls back in at full speed until it reaches the other limit. If you connect both wires to GND, the rod stops moving.

※ NOTE THAT:

A DC motor, servo motor or stepper motor without gears cannot hold its position under load when the power is off. A linear actuator can. Its internal gears and lead screw keep the rod in place, even with no power.

Speed

If you give the actuator less than 12V, it still moves, but more slowly. Changing the supply voltage in a real circuit is hard, so this method is rarely used. Instead, you keep the voltage fixed and switch it on and off very fast with a PWM signal. A higher PWM duty cycle makes the rod move faster.

How to control linear actuator

How to Control a Linear Actuator with ESP32 S3 Uno

In most projects, you want three things from the actuator. You want it to extend at full speed, retract at full speed, and, if needed, move at a slower speed.

The ESP32 S3 Uno can make the control signals, but its pins give only 3.3V and a few milliamps. That is far too weak to move an actuator. So you put a driver between the board and the actuator.

The driver does two jobs. First, it boosts the weak signal from the board so it can power the actuator. Second, it swaps the supply polarity based on a second signal from the board, and this decides whether the rod extends or retracts.

※ NOTE THAT:

This guide works for any linear actuator. The 12V model is only an example. Even with a small 5V actuator you still need a driver, because an ESP32 S3 Uno pin outputs only 3.3V and cannot supply the current an actuator needs. Never connect an actuator straight to a GPIO pin.

This guide uses the L298N driver. Other chips and modules, such as the L293D, can also drive a linear actuator.

Overview of L298N Driver

The L298N is a cheap and popular driver board. It can run linear actuators, DC motors and stepper motors. Once you know its pins, the wiring is simple.

L298N Driver Pinout

L298N Driver Pinout

The L298N has two channels, A and B. Each channel drives one actuator, so you can move two actuators at the same time, each on its own. The module has 13 pins in total.

Common pins for both channels

The VCC pin brings power to the actuator and accepts 5V to 35V. The GND pin is the common ground and goes to 0V. The 5V pin powers the logic chip on the module, and you can feed it from the 5V pin of the ESP32 S3 Uno.

Channel A pins

The ENA pin sets the speed of actuator A. Remove its jumper and connect it to a PWM pin to change how fast the rod moves. The IN1 and IN2 pins set the direction. When one is HIGH and the other is LOW, the actuator extends or retracts. When both are HIGH or both are LOW, it stops. Actuator A connects to OUT1 and OUT2.

Channel B pins

Channel B works the same way. ENB sets the speed of actuator B when you remove its jumper and give it a PWM signal. IN3 and IN4 set the direction: one HIGH and one LOW makes the rod move, and equal levels make it stop. Actuator B connects to OUT3 and OUT4.

Power inputs and jumpers

The L298N has two power inputs. The VCC and GND pins power the actuator, from 5V to 35V. The 5V and GND pins power the module itself, from 5V to 7V. The module also has three jumpers for special uses. To keep things simple, remove all of them.

With one ESP32 S3 Uno and one L298N, you can control two linear actuators at once. Each actuator needs only three pins on the board.

※ NOTE THAT:

This tutorial controls one actuator on channel A. A second actuator on channel B works in the same way.

ESP32 S3 Uno Pinout

The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the Uno header pins (D6, D7, D13, 5V…) and their GPIO numbers when you wire the L298N driver.

ESP32 S3 Uno pinout diagram

How To Control Linear Actuator

Now you connect everything and learn the few lines of code that move the rod. Each part below shows one small action you can reuse in your own projects.

Wiring Diagram

Remove all three jumpers from the L298N module before you start. Then wire the board, the driver and the actuator as shown below.

The wiring diagram between ESP32 S3 Uno Linear Actuator L298N Driver

This image is created using Fritzing. Click to enlarge image

L298N Pin ESP32 S3 Uno Pin
ENA D13 (GPIO12)
IN1 D7 (GPIO14)
IN2 D6 (GPIO3)
5V 5V
GND GND

Connect the actuator wires to OUT1 and OUT2. Connect the positive wire of the 12V power adapter to the VCC pin of the L298N, and its negative wire to the GND pin of the L298N.

WARNING

D6 (GPIO3) is a boot strapping pin on the ESP32 S3 Uno. The chip reads it at power-up to choose its boot mode. The L298N input normally does not disturb it, but if the board does not boot or cannot upload code, unplug the IN2 wire, upload the code, and then plug it back in.

※ NOTE THAT:

The ESP32 S3 Uno sends 3.3V signals to the ENA, IN1 and IN2 pins. The L298N reads 3.3V as HIGH, so no level shifter is needed. All signals go OUT of the board, so no 5V ever reaches an ESP32 S3 Uno pin.

How To Make Linear Actuator Expand/Retract

The direction comes from the levels you write to IN1 and IN2. The table below shows every combination for channel A.

IN1 pin IN2 pin Direction
LOW LOW Linear Actuator A stops
HIGH HIGH Linear Actuator A stops
HIGH LOW Linear Actuator A extends
LOW HIGH Linear Actuator A retracts

Extend the actuator

digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW);

Retract the actuator

digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, HIGH);

※ NOTE THAT:

If the rod moves the wrong way, the actuator wires on OUT1 and OUT2 are swapped. You can swap the two wires, or you can swap the IN1 and IN2 levels in the code.

How To Stop Linear Actuator from Extending or Retracting

The actuator stops by itself when it reaches its fully extended or fully retracted point. You can also stop it earlier, anywhere along its stroke. There are two ways to do this.

Set the speed to zero

analogWrite(ENA_PIN, 0);

Set IN1 and IN2 to the same level

Both LOW:

digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW);

Or both HIGH:

digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, HIGH);

How To Control the Speed of Linear Actuator via L298N Driver

To change the speed, you send a PWM signal to the ENA pin instead of a fixed HIGH. The L298N amplifies this signal and drives the actuator with it.

  1. Connect an ESP32 S3 Uno pin (here D13) to the ENA pin of the L298N.
  2. Call analogWrite() on that pin to send the PWM signal.
analogWrite(ENA_PIN, speed); // Set PWM duty cycle on ENA_PIN from 0 (0% on) to 255 (100% on) representing actuator speed

The speed value goes from 0 to 255. A value of 0 stops the actuator, and 255 moves it at full speed. On the ESP32 S3 Uno, analogWrite() uses the same 0 to 255 range as on other Arduino boards.

ESP32 S3 Uno Example Code

This sketch is a simple full-speed test. It pushes the rod all the way out, holds it there, pulls it all the way back in, holds it again, and repeats.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-actuator */ #define ENA_PIN 12 // The ESP32 S3 Uno pin GPIO12 (D13) connected to the EN1 pin L298N #define IN1_PIN 14 // The ESP32 S3 Uno pin GPIO14 (D7) connected to the IN1 pin L298N #define IN2_PIN 3 // The ESP32 S3 Uno pin GPIO3 (D6) connected to the IN2 pin L298N void setup() { // initialize digital pins as outputs. pinMode(ENA_PIN, OUTPUT); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); digitalWrite(ENA_PIN, HIGH); } // the loop function runs over and over again forever void loop() { // extend the actuator digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW); delay(20000); // actuator will stop extending automatically when reaching the limit // retracts the actuator digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, HIGH); delay(20000); // actuator will stop retracting automatically when reaching the limit }

The ENA pin is set HIGH once in setup(), so the actuator always runs at full speed. Each move lasts 20 seconds, which is long enough for most actuators to reach their limit and stop on their own. The pin numbers in the code are GPIO numbers: 12 for D13, 14 for D7 and 3 for D6.

Detailed Instructions

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Remove all three jumpers from the L298N module.
  3. Wire it up as shown in the diagram.
  4. Connect the board to your computer with a USB Type-C cable.
  5. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  6. Copy the code above and paste it into Arduino IDE.
  7. Upload the code by clicking the Upload button.
  8. Plug in the 12V adapter and watch the actuator. The rod extends and stops at its limit, holds its position for a while, retracts and stops at its other limit, then holds again. This cycle repeats forever.
  9. Tip: if your actuator is slow and does not reach its limit in 20 seconds, make the delay() values larger. You can find the full-stroke time in the actuator's datasheet.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

Summary

In this ESP32 S3 Uno tutorial, you drove a linear actuator through an L298N driver. You wired the driver, made the rod extend and retract with two direction pins, stopped it in two ways, and set its speed with a PWM signal on the ENA pin. These skills work for any actuator without feedback. You can now use them to build your own DIY automation projects, such as a motorized lid, a lifting platform or a window opener.

FAQ

Can I connect a linear actuator directly to an ESP32 S3 Uno pin?

No. An ESP32 S3 Uno pin gives only 3.3V and a few milliamps, while an actuator needs much more current, often 1A or more. The motor inside can also send voltage spikes back into the pin and damage the board. Always use a driver such as the L298N.

Does the L298N work with the 3.3V signals of the ESP32 S3 Uno?

Yes. The L298N logic inputs see about 2.3V or more as HIGH, so a 3.3V signal is enough for ENA, IN1 and IN2. You do not need a level shifter, because the signals only go from the board to the driver.

Can I power the actuator from the 5V pin of the ESP32 S3 Uno?

No. A 12V actuator needs its own 12V supply. Even a 5V actuator draws too much current for the board or the USB port, and it can reset the board. Use a separate adapter for the actuator and connect its ground to the board ground through the L298N GND pin.

Does the actuator keep its position when the power is off?

Yes. The gears and lead screw inside a linear actuator lock the rod in place. That is why you can stop it halfway and it will hold a load without any power, unlike a DC motor without gears.

Can I use other pins instead of D13, D7 and D6?

Yes. Almost every ESP32 S3 Uno pin can output PWM, so ENA, IN1 and IN2 can go to other free pins. Just change the GPIO numbers in the code. Pins like D4 (GPIO19), D5 (GPIO20) or D8 (GPIO21) are good choices because they are not boot strapping pins.

What if my project needs more pins than the Uno headers give, for example for a second actuator?

The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 offer I/O, PWM and analog. GPIO45 and GPIO35 to GPIO42 offer I/O and PWM. GPIO47 and GPIO48 are output only, with PWM. Solder pin headers to use them and write the GPIO number in code. For a second actuator, GPIO35 to GPIO42 work well for ENB, IN3 and IN4. Be careful with two things. First, GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Second, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.

Troubleshooting

Problem Possible Cause Solution
No COM port or upload fails USB driver missing or board not in download mode Install the CP210x or CH340 driver. Or hold BOOT, press RESET, then release BOOT and upload again
Board does not boot or upload with the driver wired IN2 on D6 (GPIO3) is pulled at power-up Unplug the IN2 wire, upload, then plug it back in
Actuator does not move at all Jumpers still on the L298N or no 12V power Remove all three jumpers and check that the 12V adapter is plugged into VCC and GND of the L298N
Actuator moves only one way IN1 or IN2 wire is loose or on the wrong pin Check that IN1 goes to D7 and IN2 goes to D6 and that the code uses GPIO14 and GPIO3
Actuator moves the wrong way Actuator wires on OUT1 and OUT2 are swapped Swap the two actuator wires or swap the IN1 and IN2 levels in the code
Actuator is very slow or weak Supply voltage too low or adapter too weak Use a 12V adapter that can give the rated current of the actuator
Board resets when the actuator starts No common ground or poor power wiring Connect the adapter GND, L298N GND and board GND together, and never power the actuator from the board
Rod does not reach the end before it turns back The delay is shorter than the full-stroke time Increase the delay() values in the code

※ 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!