Arduino - Actuator with Feedback

In a previous tutorial, we have learned about the linear actuator without feedback. In this tutorial, we are going to learn about the linear actuator with feedback (also called the feedback linear actuator). The feedback from the linear actuator provides the information to identify the position of its stroke, and then control the position. In detail, we are going to learn:

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×12V Linear Actuator with Feedback
1×L298N Motor Driver Module
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Recommended) Breadboard Shield For Arduino Uno
1×(Recommended) Enclosure For Arduino Uno

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

About Feedback Linear Actuator

A feedback linear actuator is a linear actuator that has the feedback signal that allows to identify its position and control it. The feedback is a potentiometer that outputs the voltage value in proportion to the stroke's position.

Feedback Linear Actuator Pinout

A Feedback Linear Actuator has 5 wires:

  • Actuator Positive wire: This wire is used to control the linear actuator by using high voltage (12V, 24V, 48V...).
  • Actuator Positive wire: This wire is used to control the linear actuator by using high voltage (12V, 24V, 48V...).
  • 5V wire: this wire is used for the feedback potentiometer. Connect this wire to 5V or 3.3V
  • GND wire: this wire is used for the feedback potentiometer. Connect this wire to GND
  • Potentiometer wire: (also called feedback wire, or output wire) this wire outputs the voltage value in proportion to the stroke's position.
Feedback Linear Actuator Pinout

How It Works

If we provide high voltage to the positive and negative wires, the stroke of the actuator will be extended or retracted. In detail, If we connect:

  • 12V (12V, 24V, 48V...) and GND to the positive wire and negative wire, respectively: the linear actuator full-speed extends until it reaches the limit.
  • 12V (12V, 24V, 48V...) and GND to the negative wire and positive wire, respectively: the linear actuator full-speed retracts until it reaches the limit.
  • While extending or retracting, if we stop power to the actuator (GND to both positive and negative wire), the actuator stops extending/retracting

※ NOTE THAT:

  • The voltage value for controlling the actuator depends on the specification of the actuator. Read the datasheet or manual to know the corresponding voltage value.
  • The actuator can keep the position even when stopping powering while carrying a load.

The voltage value in the potentiometer wire is proportional to the position of stroke on the actuator. By measuring this voltage, we can know the stroke's position.

Wiring Diagram

Please remove all three jumpers on the L298N module before wiring.

Arduino Linear Actuator L298N Driver Wiring Diagram

This image is created using Fritzing. Click to enlarge image

How to control extend/retract a linear actuator

See Arduino - Actuator tutorial

How to find the position of the linear actuator

The below shows how to identify the position of stroke on a linear actuator.

Calibration

  • Identify the length of the actuator's stroke (in millimeter) by measuring (using a ruler) or reading the datasheet
  • Identify the output values when the linear actuator is fully extended and fully retracted by running the below code
/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-actuator-with-feedback */ // the code for getting the feedback when the actuator fully extended and retracted #define ENA_PIN 9 // the Arduino pin connected to the EN1 pin L298N #define IN1_PIN 6 // the Arduino pin connected to the IN1 pin L298N #define IN2_PIN 5 // the Arduino pin connected to the IN2 pin L298N #define POTENTIOMETER_PIN A0 // the Arduino pin connected to the potentiometer of the actuator void setup() { Serial.begin(9600); // initialize digital pins as outputs. pinMode(ENA_PIN, OUTPUT); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); digitalWrite(ENA_PIN, HIGH); } void loop() { // extend the actuator digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW); delay(20000); // wait for actuator fully extends. It will stop extending automatically when reaching the limit // read the analog in value: int POTENTIOMETER_MAX = analogRead(POTENTIOMETER_PIN); Serial.print("POTENTIOMETER_MAX = "); Serial.println(POTENTIOMETER_MAX); // retracts the actuator digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, HIGH); delay(20000); // wait for actuator fully extends. It will stop retracting automatically when reaching the limit int POTENTIOMETER_MIN = analogRead(POTENTIOMETER_PIN); Serial.print("POTENTIOMETER_MIN = "); Serial.println(POTENTIOMETER_MIN); }
  • You will see the log on Serial Monitor as below example
COM6
Send
POTENTIOMETER_MAX = 987 POTENTIOMETER_MIN = 13
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Write down these values
  • If the min/max values are swapped, swap IN1_PIN and IN2_PIN
  • Update three value on the below code
  • Arduino code that calculate the position of the actuator

    /* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-actuator-with-feedback */ #define ENA_PIN 9 // the Arduino pin connected to the EN1 pin L298N #define IN1_PIN 6 // the Arduino pin connected to the IN1 pin L298N #define IN2_PIN 5 // the Arduino pin connected to the IN2 pin L298N #define POTENTIOMETER_PIN A0 // the Arduino pin connected to the potentiometer of the actuator #define STROKE_LENGTH 102 // PLEASE UPDATE THIS VALUE (in millimeter) #define POTENTIOMETER_MAX 987 // PLEASE UPDATE THIS VALUE #define POTENTIOMETER_MIN 13 // PLEASE UPDATE THIS VALUE void setup() { Serial.begin(9600); // initialize digital pins as outputs. pinMode(ENA_PIN, OUTPUT); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); digitalWrite(ENA_PIN, HIGH); } void loop() { // extend the actuator digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW); int potentiometer_value = analogRead(POTENTIOMETER_PIN); int stroke_pos = map(potentiometer_value, POTENTIOMETER_MIN, POTENTIOMETER_MAX, 0, STROKE_LENGTH); Serial.print("The stroke's position = "); Serial.print(stroke_pos); Serial.println(" mm"); }
    • Update the three calibrated values to the code
    • Upload the code to Arduino
    • See the result on Serial Monitor
    COM6
    Send
    The stroke's position = 2 mm The stroke's position = 35 mm The stroke's position = 43 mm The stroke's position = 60 mm The stroke's position = 68 mm The stroke's position = 79 mm The stroke's position = 83 mm The stroke's position = 96 mm The stroke's position = 100 mm
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

    How to control a linear actuator to a specific position

    /* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-actuator-with-feedback */ #define ENA_PIN 9 // the Arduino pin connected to the EN1 pin L298N #define IN1_PIN 6 // the Arduino pin connected to the IN1 pin L298N #define IN2_PIN 5 // the Arduino pin connected to the IN2 pin L298N #define POTENTIOMETER_PIN A0 // the Arduino pin connected to the potentiometer of the actuator #define STROKE_LENGTH 102 // PLEASE UPDATE THIS VALUE (in millimeter) #define POTENTIOMETER_MAX 987 // PLEASE UPDATE THIS VALUE #define POTENTIOMETER_MIN 13 // PLEASE UPDATE THIS VALUE #define TOLERANCE 5 // in millimeter int targetPosition_mm = 50; // in millimeter void setup() { Serial.begin(9600); // initialize digital pins as outputs. pinMode(ENA_PIN, OUTPUT); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); digitalWrite(ENA_PIN, HIGH); } void loop() { int potentiometer_value = analogRead(POTENTIOMETER_PIN); int stroke_pos = map(potentiometer_value, POTENTIOMETER_MIN, POTENTIOMETER_MAX, 0, STROKE_LENGTH); Serial.print("The stroke's position = "); Serial.print(stroke_pos); Serial.println(" mm"); if (stroke_pos < (targetPosition_mm - TOLERANCE)) ACTUATOR_extend(); else if (stroke_pos > (targetPosition_mm + TOLERANCE)) ACTUATOR_retract(); else ACTUATOR_stop(); } void ACTUATOR_extend() { digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW); } void ACTUATOR_retract() { digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, HIGH); } void ACTUATOR_stop() { digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW); }

    Video Tutorial

    We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

    The Best Arduino Starter Kit

    ※ OUR MESSAGES