Arduino Nano - Actuator

This tutorial instructs you how to use Arduino Nano to control Linear Actuator. In detail, we will learn:

There are two kinds of linear actuators:

This tutorial is for linear actuator without feedback. If you are interested in learning about linear actuator with feedback, please refer to the Arduino Nano - Actuator with Feedback tutorial.

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×Linear Actuator
1×L298N Motor Driver Module
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino Nano
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
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. We appreciate your support.

Overview of Linear Actuator

Linear Actuator Extend Retract

Linear Actuator Pinout

A Linear Actuator has two wires, typically:

  • The Positive wire is usually red
  • The Negative wire is usually black
Linear Actuator pinout

How It Works

When purchasing a linear actuator, it is essential to be aware of the voltage requirement. For instance, let us consider a 12V linear actuator.

When you power the 12V linear actuator by a 12V power source:

  • Connect 12V to the positive wire and GND to the negative wire: the linear actuator full-speed extends until it reaches the limit.
  • Connect 12V to the negative wire and GND to the positive wire: the linear actuator full-speed retracts until it reaches the limit.

When power is cut to the actuator, while it is in the process of extending or retracting, the movement will cease.

※ NOTE THAT:

For DC motor, servo motor, and stepper motor without gearing, when a load is present, if the power is cut off, they are unable to maintain their position. In contrast, an actuator can keep its position even when the power is no longer supplied while it is carrying a load.

If the voltage of the power supply to a linear actuator is below 12V, the linear actuator will still extend and retract, but not at its maximum speed. Changing the voltage of the power source can alter the speed of the linear actuator, but this method is not usually used due to the difficulty in controlling the voltage. A more practical approach is to keep the voltage of the power source fixed and control the speed of the linear actuator using a PWM signal. The higher the duty cycle of the PWM, the faster the linear actuator will extend and retract.

How to control linear actuator

How to control a linear actuator using Arduino Nano

Controlling a linear actuator involves:

  • Extending the linear actuator at its highest velocity.
  • Retracting the linear actuator at its highest velocity.
  • (Optional) Regulating the extending/retracting speed.

Arduino Nano can generate a signal to control the linear actuator, but it has low voltage and current. Therefore, a hardware driver is necessary to be placed between Arduino Nano and the linear actuator in order to:

  • Amplify the control signal from Arduino Nano
  • Receive another control signal from Arduino Nano to switch the polarity of the power supply for direction control.

※ NOTE THAT:

  • This tutorial can be used with any type of linear actuator. 12V linear actuator is just one example.
  • When controlling a 5V linear actuator, even though the Arduino Nano pin outputs 5V (which is the same as the linear actuator voltage), a driver is still required between the Arduino Nano and linear actuator because the Arduino Nano pin does not provide enough current for the linear actuator.

There are numerous types of chips and modules such as L293D and L298N that can be used for linear actuator drivers. For this tutorial, we will be utilizing the L298N driver.

※ NOTE THAT:

You can also use relays as a driver. However, it needs four relays to control a single linear actuator (both extend and retract).

Overview of L298N Driver

The L298N Driver can be utilized to regulate a linear actuator, DC motor, and stepper motor. This tutorial instructs you how to use it to control a linear actuator.

L298N Driver Pinout

L298N Driver pinout

The L298N Driver has two channels, labelled as A and B. This allows it to independently control two linear actuators simultaneously. Suppose linear actuator A is connected to channel A and linear actuator B is connected to channel B. The L298N Driver has 13 pins in total.

The common pins for both channels:

  • VCC pin: This pin provides power for the linear actuator and can range from 5 to 35V.
  • GND pin: This is a common ground pin and should be connected to 0V (GND).
  • 5V pin: This pin supplies power for the L298N module and can be supplied by 5V from an Arduino Nano.

Channel A pins:

  • ENA pins: These pins are used to adjust the speed of linear actuator A. By removing the jumper and connecting this pin to a PWM input, we can control the extending/retracting speed of linear actuator A.
  • IN1 & IN2 pins: These pins are used to determine the moving direction of a linear actuator. When one of them is HIGH and the other is LOW, the linear actuator will extend or retract. If both the inputs are either HIGH or LOW, the linear actuator will cease movement.
  • OUT1 & OUT2 pins: These pins are connected to linear actuator A.

Channel B pins:

  • ENB pins: They are used to control the speed of linear actuator B. By removing the jumper and connecting this pin to a PWM input, we can adjust the speed of extension/retraction of linear actuator B.
  • IN3 & IN4 pins: These pins are utilized for controlling the direction of a linear actuator. When one of them is set to HIGH and the other to LOW, the linear actuator will extend or retract. If both the inputs are either HIGH or LOW, the linear actuator will cease to move.
  • OUT3 & OUT4 pins: These pins are connected to a linear actuator.

The L298N driver has two power inputs:

  • One for the linear actuator (VCC and GND pins) with a voltage range of 5 to 35V.
  • One for the internal operation of the L298N module (5V and GND pins) with a voltage range of 5 to 7V.

Remove all the jumpers from the L298N driver for simplicity.

We can manage two linear actuators separately simultaneously by utilizing an Arduino Nano and an L298N Driver. For controlling each linear actuator, we require just three pins from Arduino Nano.

※ NOTE THAT:

The remainder of this tutorial will focus on controlling a linear actuator using channel A. Controlling the other linear actuator is similar.

How To Control Linear Actuator

This tutorial instructs you how to manage a Linear Actuator using an L298N driver and Arduino Nano.

Wiring Diagram

Take away all three jumpers from the L298N module prior to connecting the wires.

The wiring diagram between Arduino Nano and Linear Actuator L298N Driver

This image is created using Fritzing. Click to enlarge image

How To Make Linear Actuator Expand/Retract

The Linear Actuator's moving direction can be managed by providing a logic HIGH/LOW to IN1 and IN2 pins. The table below explains how to control the direction in both channels.

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
  • Increase the length of Linear Actuator A.
digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW);
  • Reverse the Linear Actuator A
digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, HIGH);

※ NOTE THAT:

The orientation of the linear actuator can be reversed by connecting the OUT1 & OUT2 pins to two pins of the actuator in a different order. To do this, it is necessary to either switch the OUT1 & OUT2 pins or alter the control signal on the IN1 and IN2 pins 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 has reached the limit.

  • Cut off the power

There are two methods to halt linear actuator:

  • Reduce the speed to 0
  • Disconnect the power supply
analogWrite(ENA_PIN, 0);
  • Sets IN1 IN2 pins to the same value, either LOW or HIGH.
digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW);

Or

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

How To Control the Speed of Linear Actuator via L298N Driver

It is easy to manage the speed of the linear actuator. Instead of setting ENA pin to HIGH, we can create a PWM signal to the ENA pin. This can be done by:

  • Linking an Arduino Nano pin to the ENA of the L298N
  • Utilizing the analogWrite() function to generate a PWM signal to the ENA pin. The L298N Driver will amplify the PWM signal to the linear actuator.
analogWrite(ENA_PIN, speed); // speed is a value from 0 to 255

The speed is a range from 0 to 255. If the speed is 0, the linear actuator ceases movement. When the speed is 255, the linear actuator extends/retracts at its highest velocity.

Arduino Nano Example Code

The code:

  • Increases the linear actuator to its maximum speed
  • Halts the linear actuator
  • Decreases the linear actuator to its maximum speed
  • Halts the linear actuator
/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-actuator */ const int ENA_PIN = 7; // The Arduino Nano pin connected to the EN1 pin L298N const int IN1_PIN = 6; // The Arduino Nano pin connected to the IN1 pin L298N const int IN2_PIN = 5; // The Arduino Nano pin connected to the IN2 pin L298N // The setup function runs once on reset or power-up 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 repeats indefinitely 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 }

Detailed Instructions

Take out all three jumpers from the L298N module.

Copy the code and open it in the Arduino IDE.

Click the Upload button in the Arduino IDE to upload the code to the Arduino Nano.

You will observe:

  • The linear actuator will extend until it reaches its limit, then it will stop.
  • The linear actuator will stay in this position for a certain amount of time.
  • The linear actuator will then retract until it reaches its limit, then it will stop.
  • The linear actuator will remain in this position for a certain amount of time.
  • This process will repeat itself.

Video Tutorial

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