BC Robotics

Getting Started With BC Robotics Relay Breakouts

  PRODUCT TUTORIAL

Our Relay Breakout boards are designed to allow microcontrollers (like the Arduino), single board computers (like the Raspberry Pi), and other low power / low current signals to switch high current / high power loads. Relays are one of the easiest ways to control a high current / high voltage load, but a relay cannot simply be connected to a microcontroller, they require several additional components to function correctly and protect the microcontroller from damage. Our breakout boards handle all of this extra circuitry in a compact, easy to use, module.

The boards are offered in a variety of coil voltages (the voltage used to power the relay) and have a wide input voltage for the relay trigger (the low power signal that controls the relay). On the relay contact side, 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:
When it comes to choosing relay breakout boards there are a few things to consider:

  • What you are controlling (The voltage and current you want to switch on and off using the relay)
  • What power you have available (To power the relay coils)
  • What is the voltage of the signal you want to trigger the relay with

How It Works

Relays can be thought of as big electronically controlled switches. Being able to control them with a microcontroller or single board computer is one of the key elements in basic automation – but it isn’t as simple as just connecting a relay to your Arduino. Powering a relay requires a lot more current than can be provided by a simple digital output from a microcontroller or single board computer. Also, when the relay coil is de-energized, the reverse voltage spike is particularly harmful to sensitive electronics! So, additional circuitry is required!

Our relay breakouts take this driver circuit and package it neatly on a single circuit board so all you need to do is plug everything in – no need to worry about transistors, diodes, or any of that! Just connect your digital outputs from your controller to the numbered inputs on the breakout along with power for the relay coil(s) and you are good to go! 

The Parts Needed

This tutorial will be requiring a few common parts: 

  1 x any BC Robotics Relay Breakout Board
  1 x Arduino, Raspberry Pi, or other control signal source
  Hookup Wires - Arduino Premium F/M Jumper Wire
  Hookup Wires - Raspberry Pi Premium F/M Jumper Wire
  Hookup Wires - Other external signal sources Mini Grabber - Female Cables
  Hookup Wires - Relay Board Breakout Cables

Controlling The Relays

There is a separate driver circuit for each relay on the board – meaning they can all be individually switched on and off. All of our relay boards can be used with as low as 3.3VDC signals, and right up to the relay coil voltage.

  • 5V Relay Breakouts will activate with 3.3 – 5VDC logic signals.
  • 12V Relay Breakouts will activate with 3.3 – 12VDC logic signals.
  • 24V Relay Breakouts will activate with 3.3. – 24VDC logic signals.

When each trigger wire on the relay breakout has 3.3V or greater applied, a transistor triggers that relay coil, in turn, making the relay switch states. We can connect a digital pin from an Arduino, Raspberry Pi, or any other compatible signal source to each of the trigger pins.

Connecting To The Relay(s) - Power & Control

Power and control signals are connected through the small Molex KK connector on the board. Each pin on this connector is labeled; VCC will be equal to the relay coil voltage (so on a 5V relay breakout, 5VDC. etc.). Ground will connect to your common ground. Each relay (if more than one on the board) will have a numbered input corresponding to the relay’s number on the board.

During the prototyping stage you may just want to stick to typical prototyping jumper wires. Beyond prototyping, we recommend switching to a cable using the proper Molex KK series connector.

  • 1 Channel Relay Breakouts use a 3 Pin Housing
  • 2 Channel Relay Breakouts use a 4 Pin Housing
  • 4 Channel Relay Breakouts use a 6 Pin Housing

Housings and Crimp Pins are available here: Molex KK SeriesWe also have pre-built cables available for each version as well:

 

 

Connecting To The Relay(s) - Contacts

On the Opposite side of the board we have large screw terminals for the relay contacts. The specific relays we use in our Relay Breakout boards are a SPDT contact configuration (Single Pole, Double Throw) meaning they have three contact pins: Normally Closed (NC), Normally Open (NO), and Common (COM). The common pin that is connected to one of the other two contact pins depending on the relay’s state.

When the relay is not powered, it is in its “Normal” state. In the normal state the Normally Closed “NC” pin is connected to the Common pin “COM”. Normally Open “NO” is left open (not connected to anything). Powering the relay coil will change the relay state, meaning the “COM” pin is now connected to “NO” and the “NC” pin is no longer connected to anything. Removing power from the relay coil, the relay reverts back to its normal state once again.

Depending on your application, connect your high current wires to the correct contacts on this side of the board.

Arduino Example:

In this example we will connect a 2 Channel 5V Relay Breakout to an Arduino and show the simplest way to switch it on and off using a microcontroller. Start by wiring the Relay Breakout as shown. For a 1 Channel Relay Breakout, a single digital pin can be used; for a 4 Channel Relay Breakout, 4 digital pins are needed. 

  • Red: Arduino “5V” Pin to Breakout Board “VCC” Pin
  • Black: Arduino “GND” Pin to Breakout Board “GND” Pin
  • Yellow: Arduino Digital I/O Pin 2 to Breakout Board “1” Pin
  • Green: Arduino Digital I/O Pin 3 to Breakout Board “2” Pin 

Now that everything is wired up, we will write the most basic code we can. It will identify what pins the relays are connected to, configure those pins as outputs, and then run a basic loop that switches them on and off one at a time. As before, if you need more or less digital pins, just adjust as needed. 

				
					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

void setup() {
    // put your setup code here, to run once:
    pinMode(relayPin1, OUTPUT); //Configure Arduino Pin 2 as an Output for Relay 1
    pinMode(relayPin2, OUTPUT); //Configure Arduino Pin 3 as an Output for Relay 2

}

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
    
    digitalWrite(relayPin2, HIGH); //Switch Relay #2 ON
    delay(1000); //Wait 1 Second
    
    digitalWrite(relayPin2, LOW); //Switch Relay #2 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, do the same for Relay 2, and continue through this loop forever. Going forward, this could be further adapted by connecting sensors or other inputs to the Arduino. These inputs could then be used to make decisions about when / how long to turn relays On/Off, forming a basic automation system. 

Raspberry Pi Example:

In this example we will connect a 1 Channel 5V Relay Breakout to a Raspberry Pi and show the simplest way to switch it on and off. Start by wiring the Relay Breakout as shown. For a 2 Channel Relay Breakout, two GPIO pins are needed; for a 4 Channel Relay Breakout, four GPIO pins are needed. In this case we are connecting our single relay to GPIO17 (BCM numbering). To figure out what pints are available on the Pi for additional relays, here is a complete pinout of the Raspberry Pi GPIO header

  • Red: Raspberry Pi “5V” Pin to Breakout Board “VCC” Pin
  • Black: Raspberry Pi “GND” Pin to Breakout Board “GND” Pin
  • Yellow: Raspberry Pi GPIO 17 to Breakout Board “1” Pin 

Now that everything is wired up, we will write the most basic Python code we can. It will import the needed software libraries, configure the Raspberry Pi GPIO pin numbering scheme, configure the correct pin as an output, and then run a basic loop that switches the relay on and off. As before, if you need more GPIO pins, just adjust as needed. 

				
					import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM) #Broadcom pin-numbering scheme
GPIO.setup(17, GPIO.OUT) #set Relay 1 output

interval = 1 # How long we want to wait while the relay is on(seconds)

GPIO.output(17, GPIO.HIGH) #turn relay 1 on
time.sleep(interval)
GPIO.output(17, GPIO.LOW) #turn relay 1 off
				
			

If we were to run this code by pressing “F5” it will turn Relay #1 on for 1 second and then switch it off. Going forwards, the amount of time the relay stays on for could be adjusted and this code could be run at a specific time or at a specific intervals of time using our Cron Tutorial, resulting in a basic scheduled on/off switch. 

6 thoughts on “Getting Started With BC Robotics Relay Breakouts”

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