BC Robotics

Getting Started With The 4 Channel Relay Breakout

  PRODUCT TUTORIAL

The 4 Channel Relay Breakout is an easy way to use your Arduino, Raspberry Pi, or other microcontroller to switch high voltages and high current loads. The board is both 3.3V and 5V logic compatible and uses 4 digital outputs to control 4 individual relays. Each relay has the common, normally open, and normally closed pin broken out to a convenient 5.0mm pitch screw terminal. If this all sounds over your head, don’t worry, we will be going into this in great detail!

A Few Considerations:
Before we jump into getting this relay breakout board hooked up there are a few points to consider.

• While this board can be used to switch mains power, it should be done so using extreme caution. This should not be done without the aid of an experienced electrician.
• This board uses through hole components that could short if the board is placed on a conductive surface. We recommend this board be mounted using the four corner mounting holes before use.

How It Works:
This breakout takes care of all the extra components required to use a relay with a microcontroller. Each relay can be individually driven on this board; when one of the input pins is set high it will trigger a transistor that will trip the corresponding relay and illuminate an indicator light. Each input can be directly connected to an Arduino (or other microcontroller / single board computer) without worry of damage.

The Parts Needed:

This tutorial will be requiring a few common parts:

Step 1 - Power To The Breakout Board

We manufacture a specific Molex Cable for this board, but you can also use standard jumper wires as well. We recommend using the Molex cable as it is keyed to prevent reverse insertion and has a locking ramp to prevent accidental removal.  

Start by orienting the Arduino and 4 Channel Breakout Board next to one another. This breakout board operates on 5VDC, since the Arduino also runs on 5VDC we can take power off of the 5VDC pin on the Arduino.

Start by finding the “5V” pin on the Arduino and running a jumper wire over to the “VCC” pin on the breakout board. The VCC is the positive (power) input for the circuit. Next, run a wire from the “GND” (ground) pin on the Arduino to the “GND” pin on the Breakout Board.

The breakout board now has power! 

14.3%

Step 2 - Connecting The Trigger Wires

Each relay on the breakout board has an individual trigger wire meaning they can all be individually switched on and off. When each trigger wire has between 3 and 5VDC applied a transistor triggers the relay coil, in turn, making the relay switch. We can connect a digital pin from the Arduino to each of the trigger pins on the Arduino Uno to control the relays.

Let’s go ahead and connect Arduino to the breakout board. We will start with digital pin 2 as pins 0 and 1 are reserved for the Arduino’s Serial Port. Arduino Digital Pin 2 can be connected to the pin marked “1” on the relay breakout board, Arduino pin 3 to “2”, Arduino pin 4, to “3”, and Arduino pin 5 to “4”.

28.6%

Step 3 - Double Check And Plug It In!

Before we give the Arduino power it is always a good idea to go over all of the connections to make sure there are no wires in the wrong spot – sometimes that can make for a very expensive mistake!

One way to avoid this problem is good wire color discipline. In other words, decide on a purpose for each color of wire and stick to them! In this example all 5V power are red wires, all grounds are black wires, and other colors are signal wires.  If you are using our 6 Pin Molex Cable with this board, this is already taken care of! This way, if you ever see a red wire going to a black wire you will know right away that something isn’t quite right!

42.8%

Step 4 - Starting The Code

				
					void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
				
			

Now that we have finished with the hookup we need to start writing some code. We will be using the Arduino IDE, this is available from https://www.arduino.cc/en/Main/Software

We will start with the “BareMinimum” sketch found by clicking “File” and selecting Examples / Basic / BareMinimum. This sketch is a great starting point as it includes the Setup and Loop functions – we will write the rest! 

57.1%

Step 5 - Understanding How To Control The Breakout Board

This breakout board is expecting to see a digital output signal on each of its 4 control pins so the code will be fairly simple to set up. When each Arduino pin is set “high” the connected relay will switch. When the Arduino pin is set “low” the relay will return to its off position.

Lets write a few lines of code and get this board up and running!

71.4%

Step 6 - Writing The Code

We are starting with the BareMinimum Sketch found in the IDE, it should look something like this: 

				
					void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
				
			

So first we will need some variables for the Arduino pins we plan to use:

				
					int relayPin1 = 2; //This is the Arduino Pin that will control Relay #1
int relayPin2 = 3; //This is the Arduino Pin that will control Relay #2
int relayPin3 = 4; //This is the Arduino Pin that will control Relay #3
int relayPin4 = 5; //This is the Arduino Pin that will control Relay #4

void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
				
			

Basically we are going to reduce the opportunity for confusion later down the road by assigning names to each of the Arduino pins. Now, instead of trying to remember that Arduino Pin 2 is Relay number 1, we will simply just refer to the variable “relayPin1” instead – much easier!

Next we will set all of the pins we are using to be digital outputs:

				
					int relayPin1 = 2; //This is the Arduino Pin that will control Relay #1
int relayPin2 = 3; //This is the Arduino Pin that will control Relay #2
int relayPin3 = 4; //This is the Arduino Pin that will control Relay #3
int relayPin4 = 5; //This is the Arduino Pin that will control Relay #4

void setup() {
// put your setup code here, to run once:
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

}
				
			

Ok, now all of the pins are set to outputs. Next we can write some code in the loop to switch a relay on and off:

				
					int relayPin1 = 2; //This is the Arduino Pin that will control Relay #1
int relayPin2 = 3; //This is the Arduino Pin that will control Relay #2
int relayPin3 = 4; //This is the Arduino Pin that will control Relay #3
int relayPin4 = 5; //This is the Arduino Pin that will control Relay #4

void setup() {
// put your setup code here, to run once:
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(relayPin1, HIGH); //Switch Relay #1 ON
delay(1000); //Wait 1 Second
digitalWrite(relayPin1, LOW); //Switch Relay #1 OFF
delay(1000); //Wait 1 Second
}
				
			

If we were to upload this code to the Arduino it will turn Relay #1 on for 1 second and then switch it off for 1 second and continue through this loop forever.

So before we do upload the code let’s use of all 4 relays to make a lot of clicking noise:

				
					int relayPin1 = 2; //This is the Arduino Pin that will control Relay #1
int relayPin2 = 3; //This is the Arduino Pin that will control Relay #2
int relayPin3 = 4; //This is the Arduino Pin that will control Relay #3
int relayPin4 = 5; //This is the Arduino Pin that will control Relay #4

void setup() {
// put your setup code here, to run once:
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(relayPin1, HIGH);
delay(1000);
digitalWrite(relayPin1, LOW);
digitalWrite(relayPin2, HIGH);
delay(1000);
digitalWrite(relayPin2, LOW);
digitalWrite(relayPin3, HIGH);
delay(1000);
digitalWrite(relayPin3, LOW);
digitalWrite(relayPin4, HIGH);
delay(1000);
digitalWrite(relayPin4, LOW);
}
				
			
85.7%

Step 7 - Upload The Code And Test

Now that all of the code has been written it can be uploaded to your Arduino! Click “Upload” button in the top left corner of the Arduino IDE and it should upload without any issues. After a few seconds the relays should start turning on and off in order one after another at a 1 second interval. 

100%

12 thoughts on “Getting Started With The 4 Channel Relay Breakout”

Leave a Reply

Your email address will not be published.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
  • Attributes
  • Custom attributes
  • Custom fields
Click outside to hide the comparison bar
Compare