Shop from Canada
Toll Free: 1-800-676-6123
Photo of a control box inside

Part II: How To Monitor Load Feedback Of A Linear Actuator?

Guest Writer
Guest Writer
PA Engineer

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

The 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 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 there go hit limits. When the linear actuator motor moves forward when it reaches the limit it will turn off the right latch. It the motor moves backward it will turn off the left latch. The code below only shows the right latch but the left latch code is the same.

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

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

The current limit is checked and the maximum limit is defined. If the limit is over then the left latch 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 II 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.

Please wait...

...