Linear actuators from Shift Automation - robust performance

How to control a linear actuator with an Arduino and relays

First posted on shiftautomation.com

Controlling a linear actuator

There are a wide range of linear actuator applications, essentially any time you want something moved without wanting to physically move it yourself. Depending on the application, and the user experience you want to provide, there are a number of ways to control a linear actuator. Quite often you will want the movement controlled manually by use of a rocker switch or remote control. But there are times where you need to add some intelligence into the system.  Any time you want to add intelligence into a linear actuator application, you can use a micro controller and relays to control the actuator.

What is an Arduino?

An Arduino is one of the most popular micro controllers available.  There are many, many alternatives, but Arduino has a relatively low learning curve and has massive amounts of community support and documentation.

Summary of how relays work

The relays we will be using to control the linear actuator are called 'Single Pole Double Throw' (SPDT) relays.  A relay is a switch that is controlled electricaly, rather than with a physical push. An easy way to think of this type of relay is to think of it like a railroad switch. 

SPDT relay is like a railroad switch

This animation shows the switch providing two paths to take.  This is essentially the same as the internal workings of a SPDT relay.  Just as trains can go in both directions, so can electricity.  Using the above diagram as a reference, you can have electrical current flow from A->B, or A->C, or in the opposite direction C->A, or B->A.

SPDT relays have three connections for the circuit that is switched.  Common, Normally Open, and Normally Closed.  Using the animation above as a reference, and assuming the train would normally travel from A->B, we can map the relay connections as:    A = Common, B=Normally Closed, C=Normally Open.

If we combine two SPDT relays, we can easily reverse the polarity of electricity going to the actuator motor.  By controlling the polarity going to the motor, we can control the direction of travel for the linear actuator.

In this tutorial we are using a 5V relay board and an Ardunio Uno.  The 5V relay means that the relays are activated by 5V, which is what most Arduinos run on.

Hooking the wires up to the Arduino relay board

I've labeled the relay connections to make it easier to follow.  NO=Normally Open, C=Common, NC=Normally Closed.

Controlling a linear actuator with an Arduino and relays

Step 1

Take a wire and cut a small section off for a pigtail. Then connect the first wire to the Normally Open connection on relay #1.  Take the pigtail and connect it from Normally Open on relay #1 to Normally Open on relay #2.  This is for our source +12VDC that will be used for the linear actuator motor.

Controlling a linear actuator with an Arduino and relays

 

Step 2

Take a wire and cut a small section off for a pigtail. Then connect the second wire to the Normally Closed connection on relay #1. Take the pigtail and connect it from Normally Closed on relay #1 to Normally Closed on relay #2.  This is for our Ground that will be used for the linear actuator motor.

Controlling a linear actuator with an Arduino and relays

 

Step 3

Take one motor wire and connect it to Common on relay #1.  Take the other motor wire and connect it to Common on relay #2.

Controlling a linear actuator with an Arduino and relays

 

Step 4

Now you can connect the first and second wire (red and black in our photo) to +12VDC and Ground respectively.  The actuator should not move, and there should be no sparks.  If the actuator starts moving, if there are sparks, or if a wire starts heating up, then something is wired incorrectly.  Disconnect the power and check through, one step at a time.

Down to business - writing some code!

There are many resources out there on how to begin programming with an Arduino, I won't try to replicate them here.  If you're not sure where to start, shoot us an email or give us a call and we'll help you out.

Here's how you want to set up your Arduino sketch:

 

//Use constants for the relay pins in case you need to change these later
const int relay1 = 6;   //Arduino pin that triggers relay #1
const int relay2 = 7;   //Arduino pin that triggers relay #2

void setup() {
  //Set pinMode to OUTPUT for the two relay pins
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  
}

We need to specify which Arduino pins are going to trigger the relays, and then set them as OUTPUT pins.

Next we want to write a few helper functions to make our code easier to read and maintain.

void extendActuator() {
    digitalWrite(relay1, HIGH);
    digitalWrite(relay2, LOW);
}

void retractActuator() {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, HIGH);
}

void stopActuator() {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
}

Now that we have our helper functions written, we can test out the functionality.

void loop() {
    extendActuator();
    delay(1000);

    stopActuator();
    delay(1000);

    retractActuator();
    delay(1000);

    stopActuator();
    delay(5000);
}

This will make the actuator extend out for 1 second, then stop for 1 second, then retract for 1 second, and then pause for 5 seconds.  Then start all over again.

If your actuator retracts when you want it to extend, you can simply swap the pin constants like this:

//Use constants for the relay pins in case you need to change these later
const int relay1 = 7;   //Arduino pin that triggers relay #1
const int relay2 = 6;   //Arduino pin that triggers relay #2

Now that you have the basics, you can make the actuator react to your own timing, sensors, or other logic you build. The possibilities are endless!

Let us know what you build, or if you have any questions.  We'll do our best to help you out. support@shiftautomation.com

If you build something you find interesting, we can post it here for all to see. Or if you run into a problem and you want some help with it, let us know. If you're stuck on something, chances are someone else is too!


Copyright 2016 - shiftautomation.com