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:

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 Negative 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

The two power wires of the actuator are driven by a BTS7960 module. This driver has one strong H-bridge. RPWM makes the stroke go out, LPWM pulls it back in, and R_EN and L_EN must be HIGH to turn the driver on. The 12V for the actuator goes into the B+ and B- screw terminals, and the actuator wires go to M+ and M-. The three small wires of the potentiometer go straight to Arduino.

BTS7960 Driver Pinout
Arduino Feedback Linear Actuator BTS7960 Driver Wiring Diagram

This image is created using Fritzing. Click to enlarge image

From To
BTS7960 RPWM Arduino pin 9
BTS7960 LPWM Arduino pin 10
BTS7960 R_EN Arduino pin 12
BTS7960 L_EN Arduino pin 11
BTS7960 VCC Arduino 5V
BTS7960 GND Arduino GND
BTS7960 B+, B- + and - of the 12V power adapter (via DC power jack)
BTS7960 M+, M- the positive and negative wires of the actuator
Actuator 5V wire Arduino 5V
Actuator GND wire Arduino GND
Actuator potentiometer wire Arduino pin A0

The 5V pin and the GND pin of Arduino now feed two wires each. A Screw Shield V2 or a Proto Screw Terminal Block Shield on the Arduino Uno makes this easy: each screw terminal holds the wires of its pin firmly. The wiring is the same as above.

Arduino Feedback Linear Actuator BTS7960 Driver Screw Shield 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 RPWM_PIN 9 // the Arduino pin connected to the RPWM pin of BTS7960 (extend) #define LPWM_PIN 10 // the Arduino pin connected to the LPWM pin of BTS7960 (retract) #define R_EN_PIN 12 // the Arduino pin connected to the R_EN pin of BTS7960 #define L_EN_PIN 11 // the Arduino pin connected to the L_EN pin of BTS7960 #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(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // no power to the actuator yet, then turn on the driver analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } void loop() { // extend the actuator analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255); 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); // retract the actuator analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 255); delay(20000); // wait for actuator fully retracts. 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
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
POTENTIOMETER_MAX = 987 POTENTIOMETER_MIN = 13
Ln 11, Col 1
Arduino Uno on COM15
2
  • Write down these values
  • If the min/max values are swapped, swap RPWM_PIN and LPWM_PIN in the code (or swap the M+ and M- wires)
  • 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 RPWM_PIN 9 // the Arduino pin connected to the RPWM pin of BTS7960 (extend) #define LPWM_PIN 10 // the Arduino pin connected to the LPWM pin of BTS7960 (retract) #define R_EN_PIN 12 // the Arduino pin connected to the R_EN pin of BTS7960 #define L_EN_PIN 11 // the Arduino pin connected to the L_EN pin of BTS7960 #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(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // no power to the actuator yet, then turn on the driver analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } void loop() { // extend the actuator analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255); 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
    ∞
    Newbiely | Arduino IDE 2.3.8
    ──
    ☐
    ✕
    File
    Edit
    Sketch
    Tools
    Help
    Arduino Uno
    Newbiely.ino
    ···
    8 Serial.println("Hello World!");
    Output
    Serial Monitor
    Message (Enter to send message to 'Arduino Uno' on 'COM15')
    New Line
    9600 baud
    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
    Ln 11, Col 1
    Arduino Uno on COM15
    2

    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 RPWM_PIN 9 // the Arduino pin connected to the RPWM pin of BTS7960 (extend) #define LPWM_PIN 10 // the Arduino pin connected to the LPWM pin of BTS7960 (retract) #define R_EN_PIN 12 // the Arduino pin connected to the R_EN pin of BTS7960 #define L_EN_PIN 11 // the Arduino pin connected to the L_EN pin of BTS7960 #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(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // no power to the actuator yet, then turn on the driver ACTUATOR_stop(); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_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(); } // extend: PWM on RPWM, LPWM is 0 void ACTUATOR_extend() { analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 255); } // retract: PWM on LPWM, RPWM is 0 void ACTUATOR_retract() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 255); } // stop (brake): RPWM and LPWM are 0 void ACTUATOR_stop() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); }

    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