Introduction: Using Relay Boards to Control Linear Actuators

About: Progressive Automations is your primary source for electric linear actuators, motion control systems and automation accessories. For over a decade, we have supplied various industries with top quality automati…

In this Instructable, we'll be learning how to use the relay boards to control linear actuators. All of the relays act the same, the only difference is how many are on the board.

Four relays can be combined with the MegaMoto control board to allow the board to control 2 actuators. The MegaMoto gives speed signals to the actuators, the relays choose the direction.

Two relays can also be used to create an H bridge to drive a motor, up to 30V, at 10A.

These relays use the input current to activate a electromagnet. The electromagnet pulls the switch from one position to the next, which allows the higher power currents on the other side of the relay to flow. In this way, a small powered circuit (Arduino control side) can control a large power circuit (actuator control).

For this project, you will need:

- 1x Arduino Uno

- 1x Relay board

- 1x MegaMoto motor controller

- M/F jumper wires

Step 1: Wiring the Board Basics

On the control side, the relays have a GND pin, followed by all the INx pins (1-8), and a Vcc pin. The relays take a fair bit of power to hold active, around 70 mA each, so it is best to use a dedicated 5v supply for this. The Arduino will struggle to provide enough power if all relays are active at once.

The amount of power the Arduino can deliver is dependent on how the Ardunio is being powered. A safe assumption is that it can provide a few hundred milliamps, which means its can power 2 relays easily, 4 relays maybe, but 8 relays definitely needs an external supply.

Control Side:

1) Connect the 5V supply to the Vcc and GND pins on the relay board.

2) Connect the INx pin to the Arduino pin that you want to use to activate the relay

- The 8 relay board have diodes beside the relays (D1, D2, D3...) that tell you which IN pin corresponds to which relay. The 2 relay board, the IN1 is the top relay, the IN2 is the bottom relay (top and bottom based on the GND, INx, and Vcc pins being on the left). The 4 relay board is clearly labeled.

3) The relays are activated when the corresponding INx pin is connected to GND

Relay Side:

1) The center screw terminal is the common (COM) connection. The top connection is the Normally Closed (NC) connection, and the bottom is the Normally Open (NO) connection.

2) If you have no connections to the INx pins, the relay will be connected between NC and COM. If you have 5V applied to the INx pin, the relay will be connected between NC and COM. Only if you connect the INx pin to GND, will the relay switch to connect NO and COM.

This step just covered basic wiring, we will go into more specific projects in other steps.

Step 2: Programming the Board Basics

With the board wired to the Arduino, we can now control it through programming.

Switching the relays in code is easy, just ensure the following steps are taken:

1) Assign the pin that the INx is connected to a variable name.

- Ex: const int firstRelay = 5;

2) Set the pin as an output in your void setup() routine.

- Ex: pinMode(firstRelay, OUTPUT);

3) Change the status of the pin using digitalWrite(). Remember, LOW activates the relay, HIGH deactivates it.

- Ex: digitalWrite(firstRelay, LOW);

NOTE: The relay board is only meant to switch at a maximum of 30 times per minute, so once every 2 seconds. Switching it faster than that will cause electrical feedback that could mess up your system.

Check out the embedded video to see an example of the relay control in action.

Step 3: Creating an H Bridge With Relays

These relays can be used to create an H bridge to control motors and actuators that are up to 30V, and draw 10A.

See the picture for a wiring diagram.

If the relays are deactivated, then both sides of the motor are connected to GND, causing a braking effect. If both are active, then both sides of the motor are connected to 12V (or a PWM signal), which also causes a braking effect. When one relay is active, that connects only one side of the motor to 12V, turning it one direction. Activating the other relay will cause the motor to turn the other direction.

If you just use 12V as the upper connection, then the motor will always move at full speed (assuming they are 12V motors). If you use a PWM signal, then you can vary the speed that the motor moves at.

Remember, the relays can only switch once every 2 seconds. This limits how fast you can start, stop, or change direction of the motor

A screenshot of sample code is included below.

In the next step, we will go over interfacing this H bridge with a MegaMoto controller to get speed control of 2 motors.

/* Sample code to use a relay board as an H bridge to control
 *  an actuator.
 * 
 * Progressive Automations, July 2015
 * 
 * This example code is in the public domain
 */
 
const int forwards = 7;
const int backwards = 6;//assign relay INx pin to arduino pin

void setup() {
 
pinMode(forwards, OUTPUT);//set relay as an output
pinMode(backwards, OUTPUT);//set relay as an output

}

void loop() {
  
 digitalWrite(forwards, LOW);
 digitalWrite(backwards, HIGH);//Activate the relay one direction, they must be different to move the motor
 delay(2000); // wait 2 seconds

 digitalWrite(forwards, HIGH);
 digitalWrite(backwards, HIGH);//Deactivate both relays to brake the motor
 delay(2000);// wait 2 seconds
 
 digitalWrite(forwards, HIGH);
 digitalWrite(backwards, LOW);//Activate the relay the other direction, they must be different to move the motor
 delay(2000);// wait 2 seconds

 digitalWrite(forwards, HIGH);
 digitalWrite(backwards, HIGH);//Deactivate both relays to brake the motor
 delay(2000);// wait 2 seconds

}

Step 4: Interfacing With MegaMoto Motor Controller

The relays can be used to allow a MegaMoto motor controller to have full control of 2 actuators. The PWM pins of the MegaMoto are used to control the speed of the actuator, the relay chooses the direction. Each motor requires two relays to choose direction.

See our MegaMoto control board Instructable for more detailed information about the motor controller.

This setup requires 7 pins on the Arduino. 2 pins for PWMA and PWMB, 1 pin for the MegaMoto enable pin, and 4 pins for the 4 relays.

The code below will extend one actuator, then retract it, then extend and retract the second actuator.

Wiring:

1) Attach the MegaMoto shield to the Arduino

2) Connect 12V to the MegaMoto

3) Wire the relay board according to the picture (Use relay 1/2 for one motor, 3/4 for the other to keep it simple)

4) Connect the motor leads to the COM connections on the relays. If the motors move the wrong direction, you can either reverse these connection, or change the pin numbers in the code (forwards1, backwards1, forwards2, backwards2)

/*  Sample code for the Robot Power MegaMoto.  This board can be stacked up to three
  times to control three motors.

  Modified by Progressive Automations, using the original example code from:
   http://www.robotpower.com/downloads

  Hardware:
  - 1 to 3 RobotPower MegaMoto control boards
  - Arduino Uno

 Wiring:
  -Connect the +/- of the actuator to the A/B motor channels
  -Connect the +/- of the power supply to the +/- BAT connections

  This example code is in the public domain.
 */

const int EnablePin1 = 8;

const int PWMPinA1 = 3;//Actuator A control
const int PWMPinB1 = 11;//Actuator B control

const int forwards1 = 5;
const int backwards1 = 4;
const int forwards2 = 7;
const int backwards2 = 6;

void setup() {

  pinMode(EnablePin1, OUTPUT);

  pinMode(PWMPinA1, OUTPUT);
  pinMode(PWMPinB1, OUTPUT);

  pinMode(forwards1, OUTPUT);
  pinMode(backwards1, OUTPUT);

  pinMode(forwards2, OUTPUT);
  pinMode(backwards2, OUTPUT);

 motor1Speed(0);//choose speed (0-255)

  motor2Speed(0);//choose speed (0-255)

}//end setup

void loop() {

  digitalWrite(EnablePin1, HIGH);//enable the motor

  motor2Speed(0);//stop 2nd motor
  motor1Direction(1);//choose direction 1 = forwards 0 = backwards
  motor1Speed(128);//choose speed (0-255)
  delay(3000);//wait 3 seconds

  motor1Direction(0);//choose direction 1 = forwards 0 = backwards
  motor1Speed(128);//choose speed (0-255)
  delay(3000);//wait 3 seconds

  motor1Speed(0);//stop 1st motor
  motor2Direction(1);//choose direction 1 = forwards 0 = backwards
  motor2Speed(128);//choose speed (0-255)
  delay(3000);//wait 3 seconds

  motor2Direction(0);//choose direction 1 = forwards 0 = backwards
  motor2Speed(128);//choose speed (0-255)
  delay(3000);//wait 3 seconds

}//end main loop

int motor1Direction(int direct)
{
  if (direct == 0)//if 0, go backwards
  {
    digitalWrite(forwards1, HIGH);//high deactivates relay
    digitalWrite(backwards1, LOW);//low activates relay
  }//end if

  else if (direct == 1) //if 1, go forwards
  {
    digitalWrite(forwards1, LOW);//low activates relay
    digitalWrite(backwards1, HIGH);//high deactivates relay
  }//end if

}//end motor1Direction

int motor2Direction(int direct)
{
  if (direct == 0)//if 0, go backwards
  {
    digitalWrite(forwards2, HIGH);//high deactivates relay
    digitalWrite(backwards2, LOW);//low activates relay
  }//end if

  else if (direct == 1) //if 1, go forwards
  {
    digitalWrite(forwards2, LOW);//low activates relay
    digitalWrite(backwards2, HIGH);//high deactivates relay
  }//end if

}//end motor2Direction

int motor1Speed(int speeed)
{
  analogWrite(PWMPinA1, speeed);//set speed of motor
}//end motor1Speed

int motor2Speed(int speeed)
{
  analogWrite(PWMPinB1, speeed);//set speed of motor
}//end motor2Speed

Step 5: Conclusion

In this Instructable we learned how to use the relay boards to control the motion of actuators. We also learned how to interface them with other control boards to expand their capabilities. These code snippets and wiring diagrams can be combined with other examples in our other Instructables to make your project however you like.


If you'd like to take a look at our selection of linear actuators, motions control systems and microcontrollers then please visit us at www.progressiveautomations.com/ for all your actuator needs! We can even build a custom actuator or control system for you based on your own custom specifications with the help of our highly trained staff of engineers! You can learn more about the custom order process right here.

Follow, Like and Subscribe!

Twitter - https://twitter.com/ProgAutoInc

Facebook - https://www.facebook.com/ProgressiveAutomation

Youtube - https://www.youtube.com/user/MrActuators