Interfacing Linear Actuator with Arduino

1,510 views

Introduction

Linear actuators are an essential component of many automation and robotics systems. Their ability to convert rotational motion into linear motion makes them ideal for various industrial, commercial, and residential applications. The Arduino microcontroller board, on the other hand, is a popular platform for building projects that require precise control and automation.

In this article, we will explore how to interface a “Linear Actuator with an Arduino” board to create a simple yet effective linear motion system.

What is Linear Actuator?

A linear actuator is a device that converts rotational motion or energy into linear motion or energy. It is commonly used in various industrial, commercial, and residential applications, such as robotics, manufacturing, automotive, medical equipment, and home automation.

The main components of a linear actuator are a motor, a lead screw, a gearbox, and a rod. The motor provides the rotational force which is transmitted to the gearbox, which in turn converts the rotational motion into linear motion via the lead screw. The rod is attached to the end of the lead screw and moves back and forth in a straight line, providing linear motion.

Hardware Components

To interface Linear Actuator with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
DC Power for Arduino1
DC Motor Driver1
Linear Actuator1
Jumper Wires1

DC Motor Driver Pinout

Linear Actuator Pinout
Linear Actuator Pinout
Pin NamePin Description
IN1 & IN2Motor A input pins. Used to control the spinning direction of Motor A
IN3 & IN4Motor B input pins. Used to control the spinning direction of Motor B
ENAEnables PWM signal for Motor A
ENBEnables PWM signal for Motor B
OUT1 & OUT2Output pins of Motor A
OUT3 & OUT4Output pins of Motor B
12V12V input from DC power source
5VSupplies power for the switching logic circuitry inside L298N IC
GNDGround pin

Linear Actuator Circuit

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoDC Motor DriverLinear Actuator
OUT3POS
OUT4NEG
D4EN 1
D5IN 1
D6IN 2

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Installing Libraries

Before you start uploading a code, download and unzip the following libraries at /Program Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

#include <elapsedMillis.h>
elapsedMillis timeElapsed;
 
int RPWM = 10;  
int LPWM = 11;
int sensorPin = A0;
 
int sensorVal;
int Speed=255;
float strokeLength = 6.0;                           //customize to your specific stroke length
float extensionLength;
 
int maxAnalogReading;
int minAnalogReading;
 
void setup() {
  pinMode(RPWM, OUTPUT);
  pinMode(LPWM, OUTPUT);
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
  maxAnalogReading = moveToLimit(1);
  minAnalogReading = moveToLimit(-1);
}
 
void loop(){
  Serial.println("Extending...");
  sensorVal = analogRead(sensorPin);
  while(sensorVal < maxAnalogReading){
    driveActuator(1, Speed);
    displayOutput();  
    delay(20);
  }
  driveActuator(0, Speed);
  delay(1000);
 
  Serial.println("Retracting...");
  sensorVal = analogRead(sensorPin);
  while(sensorVal > minAnalogReading){
    driveActuator(-1, Speed);
    displayOutput();  
    delay(20);
  }
  driveActuator(0, Speed);
  delay(1000);
}
 
int moveToLimit(int Direction){
  int prevReading=0;
  int currReading=0;
  do{
    prevReading = currReading;
    driveActuator(Direction, Speed);
    timeElapsed = 0;
    while(timeElapsed < 200){ delay(1);}           //keep moving until analog reading remains the same for 200ms
    currReading = analogRead(sensorPin);
  }while(prevReading != currReading);
  return currReading;
}
 
float mapfloat(float x, float inputMin, float inputMax, float outputMin, float outputMax){
 return (x-inputMin)*(outputMax - outputMin)/(inputMax - inputMin)+outputMin;
}
 
void displayOutput(){
  sensorVal = analogRead(sensorPin);
    extensionLength = mapfloat(sensorVal, float(minAnalogReading), float(maxAnalogReading), 0.0, strokeLength);
    Serial.print("Analog Reading: ");
    Serial.print(sensorVal);
    Serial.print("\tActuator extension length: ");
    Serial.print(extensionLength);
    Serial.println(" inches");  
}
 
void driveActuator(int Direction, int Speed){
  switch(Direction){
    case 1:       //extension
      analogWrite(RPWM, Speed);
      analogWrite(LPWM, 0);
      break;
   
    case 0:       //stopping
      analogWrite(RPWM, 0);
      analogWrite(LPWM, 0);
      break;
 
    case -1:      //retraction
      analogWrite(RPWM, 0);
      analogWrite(LPWM, Speed);
      break;
  }
}

Code Explanation

This is an Arduino code that demonstrates how to interface a linear actuator with an Arduino board. The code uses an external library called “elapsedMillis.h” to keep track of time elapsed. The linear actuator is controlled by two PWM pins (RPWM and LPWM), and a potentiometer is used to measure the actuator’s extension length.

The code starts by initializing the pins and setting up the serial communication. Then, it moves the actuator to its maximum and minimum extension limits to calibrate the system. The loop function then extends and retracts the actuator by reading the potentiometer value and controlling the PWM pins accordingly.

The “moveToLimit” function is used to find the maximum and minimum potentiometer values, which correspond to the maximum and minimum extension lengths of the actuator. The “mapfloat” function is used to convert the potentiometer value to the actual extension length in inches. The “displayOutput” function prints the current potentiometer value and the corresponding extension length on the serial monitor.

Overall, this code provides a basic framework for interfacing a linear actuator with an Arduino board and controlling its motion. With some customization, it can be used in various automation and robotics applications that require linear motion control.

Applications

Here are some applications of linear actuators:

  • Industrial automation: Linear actuators are commonly used in industrial automation systems, such as assembly lines, packaging machinery, and material handling equipment.
  • Robotics: Linear actuators are used in robotic systems for precision motion control, such as in grippers, joints, and linear slides.
  • Automotive: Linear actuators are used in automotive applications, such as power seat adjustments, power tailgates, and convertible top actuators.
  • Medical equipment: Linear actuators are used in medical equipment, such as hospital beds, patient lifts, and surgical tables, for precise positioning and movement control.
  • Aerospace: Linear actuators are used in aerospace applications, such as wing flaps and landing gear control systems.
  • Home automation: Linear actuators are used in home automation systems, such as motorized window blinds, TV lifts, and adjustable furniture.
  • Agriculture: Linear actuators are used in agricultural equipment, such as irrigation systems, plows, and fertilizer spreaders.
  • Marine: Linear actuators are used in marine applications, such as boat steering systems and hatch actuators.

Conclusion.

A linear actuator with an Arduino board can provide a simple and effective solution for automating linear motion systems. The versatility and flexibility of both components allow for endless possibilities in designing and implementing automation systems.