Photo of a control box inside

How To Monitor Load Feedback Of A Linear Actuator Part 2

Guest Writer
Guest Writer
PA Engineer

Welcome to Part 2 of our guide on how to monitor the load feedback of a linear actuator. In Part 1 we went over the wiring process and the basic coding needed for the example. In today's guide we will be going over in the detail the different sections of the coding as well as some ways to edit it to your liking. To begin we will be looking at the latchButtons() section of code.

First thing we want to see is the button debouncing, so when the left button is pressed that time since the previous button press needs to be calculated. To do this we'll have to utilize the last value that was stored in the code, then use the millis() function to check the time. When the time is greater then the debounce time the function will then check if the actuator is able to extend. Once both conditions are met the function will be able to continue.

if (digitalRead(buttonLeft)==LOW)//left is forwards

{
currentTimedebounce = millis() - lastButtonpress;// check time since last press
if (currentTimedebounce > debounceTime && dontExtend == false)//once you've tripped dontExtend, ignore all forwards presses
{
leftlatch = !leftlatch;// if motor is moving, stop, if stopped, start moving
firstRun = true;// set firstRun flag to ignore current spike
fullyRetracted = false; // once you move forwards, you are not fully retracted
lastButtonpress = millis();//store time of last button press
return;
}//end if
}//end btnLEFT


The next section is the loop within the motorForward() function, specifically the two delays. The loop starts by engaging the motor controller, which starts the linear actuator motor. If it's the first through the loop there will be a larger delay. The delay ignores the current spike that occurs when the motor is activated. Make sure to not set the delay too big because you will have no control over it once it starts. When the motor starts, the getFeedback() section is used to check the current sensor.

while (dontExtend == false && leftlatch == HIGH)  {

digitalWrite(EnablePin, HIGH);
analogWrite(PWMPinA, speeed);
analogWrite(PWMPinB, 0);//move motor
if (firstRun == true) delay(firstfeedbacktimedelay);
else delay(feedbacktimedelay); //small delay to get to speed
getFeedback();
firstRun = false;

latchButtons();
}//end while

Photo of a control box inside

Next, we'll be going over the sections in the get feedback() routine, which starts by reading the analog pin that connects to the sensor. It begins by checking if the motor is at its limits and the code knows when its at its limits when the current reads 0. Unfortunately, there can be a false reading sometimes so it's important to set a counter. This counter code has to count up to the hitLimitsmax before the motor stops and if it counts less then that it will reset.

 

if (CRaw == 0 && hitLimits < hitLimitsmax) hitLimits = hitLimits + 1;  


else hitLimits = 0; // check to see if the motor is at the limits and the current has stopped


After that is the hit limits. When the linear actuator motor moves forward when it reaches the limit it will turn off the rightlatch. It the motor moves backward it will turn off the leftlatch. The code below only shows the rightlatch but the leftlatch code is the same.

 

if (hitLimits == hitLimitsmax && rightlatch == HIGH)  {

rightlatch = LOW;
hitLimits = 0;
}//end if


The current limit is checked its maximum limit. If the limit is over then the leftlatch will be turned off and the motor will no longer extend. In order to start the extension the motor needs to be reversed.

 

if (CRaw > maxAmps)  {

dontExtend = true;
leftlatch = LOW; //stop if feedback is over maximum
}//end if

That brings us to the end of Part 2 of monitoring the load feedback of a linear actuator. We went into detail on specific sections of the code this time and explained how they work. If you'd like to order any units we used in this example you can order online or contact us to order by phone. If you have any questions or concerns regarding our products we are always ready to help as well.