Position Control of a Linear Electric Actuator w/ Analog Sensor

In today's post we will be going over how to control the position of a linear electric actuator by utilizing an analog sensor, in this case a potentiometer. For this example we'll be using one of our PA-14P electric actuators,  an Arduino Uno, a MegaMoto motor controller, a separate potentiometer and a breadboard. Before we do anything we will need to wire everything together in order for it to function. The wiring procedure goes like this:


1) Connect the MegaMoto motor controller to the Arduino Uno

-Connect the Enable jumper pin to D8

-Connect PWM pin A to D11

-Connect PWM pin B to D3

-Make sure your sensor is not on A0 or A1.

2) With your 12V power supply connect the BAT+ to Vin

3) Connect your linear electric actuator to the MOTA and MOTB points.

4) For this next part we recommend using a breadboard to make the next connections much simpler. Connect the electric actuators POT wires like so:

-Connect the Yellow wire to 5V

-Connect the White wire to GND

-Connect the Blure wire to A1

5) With the separate potentiometer we want to connect it like so:

-Connect one side to 5V

-Connect other side to GND

-Connect the middle pin to A0.

6) Finally connect the 12V power supply to the BAT+ and BAT- points on the MegaMoto motor controller.


With the wiring finished we can know start the programming aspect of this example. With this program the goal is get a reading of the potentiometer and the actuators position, then compare them. If the positions are different then all you need to do is extend or retract the actuator until they match. Use this code below to view the potentiometers position and match it up with the actuator.

const int feedback = A0; //potentiometer from actuator
const int pot = A1; //pot from throttle

const int enable = 8;
const int PWMA = 11;
const int PWMB = 3;

int actMax = 760;
int actMin = 250;//positions of actuator

int potMin = 0;
int potMax = 1023;

int precision = 2;//how close to final value to get
int checkingInterval = 50;//how often position is checked (milliseconds)

int rawcurrentPosition = 0;
int currentPosition = 0;
int rawdestination = 0;
int destination = 0;
int difference = 0;//values for knowing location

void setup()
  pinMode(feedback, INPUT);//feedback from actuator
  pinMode(pot, INPUT);//feedback from potentiometer
  pinMode(enable, OUTPUT);
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);//three pins for MegaMoto

void loop()
    destination = getDestination(); 
    currentPosition = analogRead(feedback);//check where you are
    Serial.print("Position    ");
    difference = destination - currentPosition;//find out how far you are from the destination
    if (currentPosition > destination) pullActuatorUntilStop(destination);// choose what action to take
    else if (currentPosition < destination) pushActuatorUntilStop(destination);
    else if (difference < precision && difference > -precision) stopActuator();
}//end void loop

int getDestination()
    rawdestination = analogRead(pot);//read the potentiometer to get the destination
    destination = map(rawdestination, potMin,potMax,actMin,actMax);//convert the potentiometer feedback to match the actuator
}//end getDestination

void pushActuatorUntilStop(int destination)
  destination = getDestination();
  int temp = analogRead(feedback); 
  difference = destination - temp;//check difference to see if continue moving, or stop

  while (difference > precision || difference < -precision)
    destination = getDestination();
    temp = analogRead(feedback); //continue checking difference
    difference = destination - temp;
  }//end while
}//end pushActuatorUntilStop

void pullActuatorUntilStop(int destination)
  destination = getDestination();
  int temp = analogRead(feedback); //check difference to see if continue moving, or stop
  difference = destination - temp;

  while (difference > precision || difference < -precision)
    destination = getDestination();
    temp = analogRead(feedback); //continue checking difference
    difference = destination - temp;
  }//end while
}//end pullActuatorUntilStop

void stopActuator()
}//end stopActuator

void pushActuator()
}//end pushActuator

void pullActuator()
}//end pullActuator


This was a basic overview of position control of a linear actuator. If you'd like to purchase anything we used in this example you can order online or contact us to order by phone. Please do not hesitate to contact us if you have any questions or concerns about our products as well, we are always ready and able to help with whatever you have in mind.


Servicing Top Brands:

Please wait...