ESP8266 - Feedback Actuator

In a prior tutorial, we discussed the linear actuator without feedback. This tutorial instructs you the feedback linear actuator (also known as the feedback linear actuator). This type of linear actuator provides information to identify the position of its stroke and control it. Specifically, we will be learning:

Hardware Preparation

1×ESP8266 NodeMCU
1×Micro USB Cable
1×12V Linear Feedback Actuator
1×L298N Motor Driver Module
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×(Optional) 5V Power Adapter for ESP8266
1×(Optional) ESP8266 Screw Terminal Adapter

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
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 Feedback Linear Actuator

A linear actuator with feedback is one that has a signal to identify its location and manage it. A potentiometer is used to generate the voltage value in relation to the stroke's position as the feedback.

Feedback Linear Actuator Pinout

A Feedback Linear Actuator has 5 wires:

  • Actuator Positive wire: This wire is used to control the linear actuator by applying high voltage (12V, 24V, 48V...).
  • Actuator Negative wire: This wire is used to control the linear actuator by applying high voltage (12V, 24V, 48V...).
  • 5V wire: this wire is used for the feedback potentiometer. It should be connected to 5V or 3.3V
  • GND wire: this wire is used for the feedback potentiometer. It should be connected to GND
  • Potentiometer wire: (also referred to as feedback wire, or output wire) this wire outputs the voltage value in accordance with the stroke's position.
Feedback Linear Actuator pinout

How It Works

.

If we supply high voltage to the positive and negative wires, the stroke of the actuator will be extended or retracted. Specifically:

  • If 12V (12V, 24V, 48V...) is connected to the positive wire and GND to the negative wire, the linear actuator will extend at full speed until it reaches the limit.
  • If 12V (12V, 24V, 48V...) is connected to the negative wire and GND to the positive wire, the linear actuator will retract at full speed until it reaches the limit.
  • If power is cut off to the actuator (GND to both positive and negative wire), the actuator will cease extending/retracting.

※ NOTE THAT:

  • The voltage required to operate the actuator is determined by its specifications. To find out the exact voltage, consult the datasheet or manual.
  • Even when the power is turned off, the actuator can maintain its position while carrying a load.

The voltage in the potentiometer wire is directly related to the stroke position of the actuator. By measuring this voltage, we can ascertain the stroke's location.

Wiring Diagram

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

The wiring diagram between ESP8266 NodeMCU and Linear Actuator L298N Driver

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

How to control extend/retract a linear actuator

Check out the ESP8266 - Actuator tutorial.

How to find the position of the linear actuator

This is an illustration of how to locate the stroke on a linear actuator.

Calibration

  • Determine the length of the actuator's stroke (in millimeters) by either measuring with a ruler or consulting the datasheet.
  • To ascertain the output values when the linear actuator is fully extended and fully retracted, execute the code below.
/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-feedback-actuator */ // The code for getting the feedback when the actuator fully extended and retracted #define ENA_PIN 7 // The ESP8266 pin connected to the EN1 pin L298N #define IN1_PIN 6 // The ESP8266 pin connected to the IN1 pin L298N #define IN2_PIN 5 // The ESP8266 pin connected to the IN2 pin L298N #define POTENTIOMETER_PIN A0 // The ESP8266 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 observe the log on Serial Monitor, as demonstrated in the example below
COM6
Send
POTENTIOMETER_MAX = 987 POTENTIOMETER_MIN = 13
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Note down the three values in the code below. If the minimum and maximum values are reversed, switch the IN1_PIN and IN2_PIN.

Make a note of the three values in the code below. If the minimum and maximum values are transposed, interchange the IN1_PIN and IN2_PIN.

ESP8266 code that calculate the position of the actuator

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-feedback-actuator */ #define ENA_PIN 7 // The ESP8266 pin connected to the EN1 pin L298N #define IN1_PIN 6 // The ESP8266 pin connected to the IN1 pin L298N #define IN2_PIN 5 // The ESP8266 pin connected to the IN2 pin L298N #define POTENTIOMETER_PIN A0 // The ESP8266 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 code with the three calibrated values.
  • Upload the code to ESP8266.
  • Check out the result on the 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

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-feedback-actuator */ #define ENA_PIN 7 // The ESP8266 pin connected to the EN1 pin L298N #define IN1_PIN 6 // The ESP8266 pin connected to the IN1 pin L298N #define IN2_PIN 5 // The ESP8266 pin connected to the IN2 pin L298N #define POTENTIOMETER_PIN A0 // The ESP8266 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

Learn More