MONITORING THE CURRENT OF A LINEAR ACTUATOR

This example code uses a MegaMoto Plus and an Arduino Uno to monitor the current of a linear actuator, however, similar products can be used as substitutions.

/*  Code to monitor the current amp draw of the actuator, and to cut power if it
  rises above a certain amount.

  Written by Progressive Automations
  August 19th, 2015

  Hardware:
  - RobotPower MegaMoto control boards
  - Arduino Uno
  - 2 pushbuttons
 */

const int EnablePin = 8;
const int PWMPinA = 11;
const int PWMPinB = 3; // pins for Megamoto

const int buttonLeft = 4;
const int buttonRight = 5;//buttons to move the motor

const int CPin1 = A5;  // motor feedback

int leftlatch = LOW;
int rightlatch = LOW;//motor latches (used for code logic)

int hitLimits = 0;//start at 0
int hitLimitsmax = 10;//values to know if travel limits were reached

long lastfeedbacktime = 0; // must be long, else it overflows
int firstfeedbacktimedelay = 750; //first delay to ignore current spike
int feedbacktimedelay = 50; //delay between feedback cycles, how often you want the motor to be checked
long currentTimefeedback = 0; // must be long, else it overflows

int debounceTime = 300; //amount to debounce buttons, lower values makes the buttons more sensitive
long lastButtonpress = 0; // timer for debouncing
long currentTimedebounce = 0;

int CRaw = 0;      // input value for current readings
int maxAmps = 0; // trip limit 

bool dontExtend = false;
bool firstRun = true;
bool fullyRetracted = false;//program logic

void setup()
{
  Serial.begin(9600);
  pinMode(EnablePin, OUTPUT);
  pinMode(PWMPinA, OUTPUT);
  pinMode(PWMPinB, OUTPUT);//Set motor outputs
  pinMode(buttonLeft, INPUT);
  pinMode(buttonRight, INPUT);//buttons
  
  digitalWrite(buttonLeft, HIGH);
  digitalWrite(buttonRight, HIGH);//enable internal pullups
  pinMode(CPin1, INPUT);//set feedback input
  
  currentTimedebounce = millis();
  currentTimefeedback = 0;//Set initial times

  maxAmps = 15;// SET MAX CURRENT HERE

}//end setup

void loop()
{
  latchButtons();//check buttons, see if we need to move

  moveMotor();//check latches, move motor in or out

}//end main loop

void latchButtons()
{
  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

  if (digitalRead(buttonRight)==LOW)//right is backwards
  {
    currentTimedebounce = millis() - lastButtonpress;// check time since last press

    if (currentTimedebounce > debounceTime)
    {
      rightlatch = !rightlatch;// if motor is moving, stop, if stopped, start moving
      firstRun = true;// set firstRun flag to ignore current spike
      lastButtonpress = millis();//store time of last button press
      return;    }//end if
  }//end btnRIGHT
}//end latchButtons

void moveMotor()
{
  if (leftlatch == HIGH) motorForward(255); //speed = 0-255
  if (leftlatch == LOW) motorStop();
  if (rightlatch == HIGH) motorBack(255); //speed = 0-255
  if (rightlatch == LOW) motorStop();

}//end moveMotor

void motorForward(int speeed)
{
  while (dontExtend == false && leftlatch == HIGH)
  {
    digitalWrite(EnablePin, HIGH);
    analogWrite(PWMPinA, speeed);
    analogWrite(PWMPinB, 0);//move motor
    if (firstRun == true) delay(firstfeedbacktimedelay); // bigger delay to ignore current spike
    else delay(feedbacktimedelay); //small delay to get to speed

    getFeedback();
    firstRun = false;
    
    latchButtons();//check buttons again
  }//end while

}//end motorForward

void motorBack (int speeed)
{
  while (rightlatch == HIGH)
  {
    digitalWrite(EnablePin, HIGH);
    analogWrite(PWMPinA, 0);
    analogWrite(PWMPinB, speeed);//move motor
    if (firstRun == true) delay(firstfeedbacktimedelay);// bigger delay to ignore current spike
    else delay(feedbacktimedelay); //small delay to get to speed
    getFeedback();

    firstRun = false;
    
    latchButtons();//check buttons again

  }//end while

  dontExtend = false;//allow motor to extend again, after it has been retracted

}//end motorBack

void motorStop()
{
  analogWrite(PWMPinA, 0);
  analogWrite(PWMPinB, 0);

  digitalWrite(EnablePin, LOW);
  firstRun = true;//once the motor has stopped, reenable firstRun to account for startup current spikes

}//end stopMotor

void getFeedback()
{
  CRaw = analogRead(CPin1); // Read current

  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 

  if (hitLimits == hitLimitsmax && rightlatch == HIGH)
  {
    rightlatch = LOW; // stop motor
    fullyRetracted = true;
  }//end if

  else if (hitLimits == hitLimitsmax && leftlatch == HIGH)
  {
    leftlatch = LOW;//stop motor
    hitLimits = 0;
  }//end if

  if (CRaw > maxAmps)
  {
    dontExtend = true;
    leftlatch = LOW; //stop if feedback is over maximum
  }//end if

  lastfeedbacktime = millis();//store previous time for receiving feedback
}//end getFeedback
CONTROLLING MULTIPLE ACTUATORS WITH THE MULTIMOTO ARDUINO SHIELD
WASP MOTOR CONTROLLER FOR LINEAR ACTUATOR CONTROL
USING RELAYS TO CONTROL LINEAR ACTUATORS
CONTROLLING THE TIMING OF A SINGLE LINEAR ACTUATORS MOTION
CONTINUOUSLY EXTEND & RETRACT A LINEAR ACTUATOR WITH BRUSHLESS DC MOTOR
PA-12 MICRO SERVO ACTUATOR SAMPLE CODES
Where Can I Find Additional Information on Your Products?

We have data sheets, user manuals, 3D models, wiring diagrams and more in our Resources and Learning Center sections.

How Can I Determine Which Progressive Automations Linear Actuator is Best Suited for My Application?
What Is Duty Cycle and How Is It Calculated?
Can I Use Your Actuators to Replace The One That I Already Have?
What Does Stroke Mean? How Am I Supposed to Know Which Size to Choose?
How Do I Know Which Force Rating Is Right for My Application?
Can I Use My Own Power Supply as a Source For My Actuators?
How Can I Control Actuators to Travel At The Same Time?
Why Is My Linear Actuator Making so Much Noise?
Can I Customize a Linear Actuator to My Specifications?
Can I Synchronize My Linear Actuators?
Are Linear Actuator Kits Available?
Will Temperature Affect My Linear Actuator?
Can I Implement One of Your Actuators Into A Third-Party Mechanism?
What Is the Pin Out For My Linear Actuator?
Can I Get 3D CAD Models for My Linear Actuator?
What Are the Control Box Options For My Actuator?
Can I Use Your Control Boxes with A Third-Party Product?
Do You Sell Wi-Fi Control Boxes?
Are All of Your Control Boxes Compatible With All Of Your Linear Actuators?
Can I Use My Own Control Box?
Do You Have Sample Coding I Could Use?
I Don’t Have a Power Source – What Can I Do?
Can I Use My Own Power Supply?
Do You Have 220 VAC Power Supplies Available?
Can I Control the Lifting Columns With A Third-Party Controller?
Can I Use Two of The Flt-11 Lifting Columns Together?
What Control Box Should I Pair with My Lifting Columns?
Are Your Table/Desk/TV Lifts Customizable?
What TV Sizes Can Your TV Lifts Hold?
What Is the Weight Capacity of Your Table/Desk Lifts?
Does My Linear Actuator Come with Mounting Brackets?
Where Can I Find a Step-By-Step Guide for My Product?
I Followed the Wiring Diagram But it’s Not Working – What Should I Do?
Flowchart For Actuator Selection
Can The FLTCON Control Boxes Work With My Actuators?
What Is Backdriving? -- What Does Dynamic and Static Load Ratings Mean? -- What Is Lateral Loading?
How Can I Place an Order?

Orders can be placed by one of the following ways:

Online: Use our online order process with options to pay by Credit Card or PayPal.

Phone: 1-800 – 676 – 6123

Email: sales@progressiveautomations.com

Do You Offer Quantity Discounts?
What Methods of Payment Do You Accept?
What Form of Currency Are Your Prices In?
How Do I Know If the Product I Want Is In Stock?
How Much Will Shipping Cost and What Methods Do You Offer?

Progressive Automations’ shipping fees are calculated based on a variety of factors including but not limited to: location, quantities, and the total weight of your order. Smaller items are shipped via parcel while larger items and bulk orders are shipped via a freight carrier service. We always endeavor to provide competitive shipping prices for all our customers.

Shipping methods are available through online and phone orders. If you wish to receive an estimated shipping cost of your order, this can be done by reviewing your final shopping cart.

What Freight Companies Do You Use?
Will I Be Charged with Any Duty Tax?
What Is Your Return Policy?
How Long Is Delivery?
Do You Offer Free Shipping?
I want the longer side of my tabletop to be on the left. Can the L shaped standing desk frame be installed on either left or right?

Yes, the L shaped standing desk is orientation-friendly and can be installed by your preference. Here is a step-by-step article that explains how this is possible: FLT-05 User Manual

How do I set the maximum/minimum heights for my standing desk frame(s)?

NOTE: The steps below may vary depending on the remote model that you have. The following instructions were made for the standard RT-11 remote. To set the maximum height for your frame, go to the desired height you would like to set and follow the steps below:

  1. Press M and see [5 -] indicated on the display
  2. Press the UP button and notice [5 -] blinks
  3. Hold the M button until you see [999] on the display
  4. The maximum height has now been set

To set the minimum height for your frame, go to the desired height you would like to set and follow the steps below:

  1. Press M and see [5 -] indicated on the display
  2. Press the DOWN button and notice [5 -] blinks
  3. Hold the M button until you see [000] on the display
  4. The minimum height has now been set

To reset the limits, follow the steps below:

  1. Press M and see [5 -] indicated on the display and release
  2. Hold the M you see [555]
  3. Limits have been reset
I have to hold down the remote buttons to get to my pre-set height. Is there a way to do this with only one press?

NOTE: The steps below may vary depending on the remote model you have. The following instructions were made for the standard RT-11 remote.

If you have to hold down the remote’s buttons to get to your pre-set height, this means that your control box is in momentary control. To set your remote to non-momentary mode, follow the steps below

  1. Make sure that there is nothing underneath your desk, as we have to enter the reset procedure
  2. Press and hold the DOWN button until the display shows [ASr]
  3. Once [ASr] is shown, press and hold down [1] and you may see two values:

    a. 10.1 = Non-momentary Mode
    b. 10.2 = Momentary Mode

  4. Complete the reset procedure by holding the DOWN button until your standing desk slightly lowers and rises.
How do I change the collision detection sensitivity?

Our standing desks have 3 settings for collision detection, and this can be set depending on your preference. To proceed, follow the steps below:

  1. Make sure that there is nothing underneath your desk as we have to enter the reset procedure
  2. Press and hold the DOWN button until the display shows [ASr]
  3. Once [ASr] is shown, press and hold the UP [ ^ ] button and you may see three values:

    a. 10.5 = 11 lbs
    b. 10.6 = 22 lbs
    c. 10.7 = 33 lbs

  4. Complete the reset procedure by holding the DOWN button until your standing desk slightly lowers and rises.
My remote is showing an error code on the display? What should I do?

We have some troubleshooting steps for you to take if you see any of the following error codes on the frames with FLTCON series control boxes:

Сheck the error code here.

If the issue you are experiencing persists after following these steps, please feel free to contact our technical product engineers at 1-800-676-6123, or send us an email at sales@progressiveautomations.com.