Qwiic Quad Relay Hookup Guide

Pages
Contributors: Elias The Sparkiest
Favorited Favorite 4

Introduction

SparkFun's Qwiic Quad Relay is a product designed for switching not one but four high powered devices from your Arduino or other low powered microcontroller using I2C. It has four relays rated up to 5 Amps per channel at 250VAC or 30VDC that are controlled by an ATtiny84A. Each channel has its own blue stat LED, silk for easy identification, and screw terminals for easy connection. The product is Qwiic enabled allowing you to easily integrate the Quad Relay with other products in the Qwiic environment, which means no solder neccessary!

SparkFun Qwiic Quad Relay

SparkFun Qwiic Quad Relay

COM-16566
$32.50
6
Before we begin! There are a number of safety precautions included in the product, but that can not account for human inexperience and error. This product and the example below interacts with HIGH AC voltage and so is intended for people experienced around, and knowledgeable about HIGH AC voltage. If that's not quite your jam, then take a look at our IoT Power Relay! It's not I2C but the IoT Power Relay contains shielding to prevent accidental shock.

Required Materials

For the example under Hardware Assembly, I used the following materials to control a load (i.e. a lamp). You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

SparkFun RedBoard Qwiic

SparkFun RedBoard Qwiic

DEV-15123
$21.50
20
Jumper Wires - Connected 6" (M/M, 20 pack)

Jumper Wires - Connected 6" (M/M, 20 pack)

PRT-12795
$2.10
2
Qwiic Cable - 100mm

Qwiic Cable - 100mm

PRT-14427
$1.50
Wall Adapter Power Supply - 5VDC, 2A (Barrel Jack)

Wall Adapter Power Supply - 5VDC, 2A (Barrel Jack)

TOL-15312
$6.50
2
USB Micro-B Cable - 6 Foot

USB Micro-B Cable - 6 Foot

CAB-10215
$5.50
15
Tactile Button Assortment

Tactile Button Assortment

COM-10302
$6.50
8
Breadboard - Mini Modular (Red)

Breadboard - Mini Modular (Red)

PRT-12044
$4.50

Additional Options

You could also use our 9 volt wall adapter if that suits your fancy and we have a number of Qwiic cable sizes to fit your needs.

Qwiic Cable - 100mm

Qwiic Cable - 100mm

PRT-14427
$1.50
Qwiic Cable - 50mm

Qwiic Cable - 50mm

PRT-14426
$0.95

Wall Adapter Power Supply - 9VDC 650mA

TOL-00298
12 Retired

Qwiic Cable - 200mm

PRT-14428
Retired

Qwiic Cable - 500mm

PRT-14429
1 Retired

Tools

You will need a flush cutter and wire stripper to remove the sheath and insulation from a cable. A Phillips head screwdriver will be required to connect the load's to a screw terminal.

Flush Cutters - Xcelite

TOL-14782
2 Retired
SparkFun Mini Screwdriver

SparkFun Mini Screwdriver

TOL-09146
$1.05
3

Self-Adjusting Wire Strippers

TOL-14872
2 Retired

Suggested Reading

If you aren't familiar with the Qwiic system, we recommend reading here for an overview.

Qwiic Connect System
Qwiic Connect System

We would also recommend taking a look at the following tutorials if you aren't familiar with them.

Serial Communication

Asynchronous serial communication concepts: packets, signal levels, baud rates, UARTs and more!

I2C

An introduction to I2C, one of the main embedded communications protocols in use today.

Hardware Overview

Revision Changes: This guide is for the Qwiic Quad Relay v2.0 [ COM-16566 ] and v1.0 [ COM-15102 ]. There are some improvements to the design for reliability but overall, they should function the same. below is a list of changes for v2.0.

  • Included a normally open jumper for the power LED.
  • Switching regulator in place of a linear regulator.
    • The switching regulator is much more efficient; no external cooling needed when powering four relays at once.
  • Improved circuitry around the relays.
    • An issue where relays on certain boards in v1.0 didn't switch completely when actuated has been resolved.
The image on the left is v2.0 while the right is v1.0. You'll notice that the circuit to regulate the voltage by the barrel jacks are different. If you flip over either version, you will find the board's version number just under the relay labeled as 4.

v2.0 v1.0
v2.0 v1.0

Power

Heads up! The circuit to regulate the voltage is different in v2.0. The maximum voltage is now 12V.

There are two separate power systems on the Quad Relay: a 5V system that powers the relays and a 3.3V system that powers the on board ATtiny84A and interfaces with a microcontroller through the four pin header or Qwiic connector.

The on board barrel jack takes a power source in a range of 7-12V. It regulates the voltage and supplies power to the 5V power system of the relays. If your wall adapter or power source is at 5 volts like our 5V/2A Wall adapter then you can close the jumper on the underside of the product labeled 5V Wall Adapter (see Jumpers section below), and this will allow you to sidestep the on board regulator to power the 5V system directly. If you decide to go with a higher voltage wall adapter, be cognizant that the voltage regulator will start to heat up. With all the relay channels turned on the Quad Relay will pull ~250mA of current and at 9 Volts, that's 2.25 Watts of power (mathematical!). Over time the regulator will get hot, but will remain functional. I suggest that if you expect to have all relay channels on for extended periods of time, that you go with a 5V power supply.

Input Power Barrel Jack

To provide 3.3V to the on board ATtiny84A you can use the plated through hole labeled 3V3 on the four pin header. Alternatively, you can plug a Qwiic connector into one of the two Qwiic connectors.

PTH Pins and Qwiic Connectors for Power

Relays

There are four single pole, double throw JZC-11F relays on the Qwiic Quad Relay. Each relay is capable of 5 Amps at 250VAC or 30VDC. These relays have an associated blue screw pin terminals that are aligned in order from left to right.

Relays

LEDs

There is a red power LED labeled PWR that indicates power from the barrel jack. There is also a blue stat LED for each relay labeled with their respective number 1-4. Whenever a relay is activated (i.e. when COM is connected to NO), the respective LED will light up.

Relays and Screw Terminals

Jumpers

There are three jumpers on the underside of the Qwiic Quad Relay.

  • LED - The first jumper is for the power LED. Close the jumper to eanble the power LED.
  • ADDR - The second is the address jumper that changes the default I2C address from 0x6D to 0x6C.
  • BYP - The thirdis the jumper labeled 5V Wall Adapter Jumper. If you intend to use a wall adapter or other power source that is below 7-15V than you can close this jumper to side step the on board voltage regulator, and provide 5V directly to the 5V power system.

Jumper Pads

Qwiic Connectors

The Qwiic connectors allow you to integrate easily into our Qwiic environment and allows you to prototype without the need for soldering! The 3.3V provided by the Qwiic connector will power the on board ATtiny84A. If you do not power the 3.3V power system this way, you can still provide power through the four pin header.

Qwiic Connectors

Board Dimensions

The board size is 3.25"x 1.85". There are 5x mounting holes on the board, four of which are on each corner of the board. The fifth mounting hole near the upper left of the board is included should you decide to attach a Qwiic enabled device using the 1.0"x1.0" sized board.

Board Dimensions

Safety Considerations

This product is designed to switch high power AC or DC and so has some inherent dangers. We've done our best to implement safety features directly into the design. To begin, the copper ground pour for the ATtiny84A circuitry is restricted to an area apart from the relays. In regards to the microcontroller, there are opto-isolators that isolate the 3.3V power system that it utilizes from the 5V power system of the relays. Next, the common pin of the relays have an air gap surrounding the pin on three sides to prevent any high voltage arcing. Finally, the traces on the relays are extra wide to handle the high amperage carrying potential of the relays.

Hardware Assembly

Introduction to Relays

Let's walk through how to setup the relay to switch on a lamp or other device, but let's begin with a short introduction into relays. A relay is a switch. However, unlike most switches, within the relay's housing there is also a switching mechanism that is isolated from the switch. This is the relay's defining feature because this separation between switching mechanism and switch, as well as the switching mechanism's low-power requirements, allows for low-power microcontrollers to activate the switching mechanism without interfacing with whatever is getting "switched". Shmow-zow!

We have three channels per relay broken out to blue screw pin terminals. The channels are labeled for their function. One is considered normally open or NO, the next channel is common or COM, and the final is normally closed or NC. The names explain the state of the channel with relation to the switch at rest. The normally closed channel is where the switch sits before the switching mechanism has been activated and conversely the normally open channel is where the switch would sit after. The common channel is, as the name implies, what the other two channels have in common. This is known as a single pole, double throw switch (SPDT). The image below helps to illustrate this characteristic of our particular relay.

SPDT Switch

When the switching mechanism is activated the thicker bar in the image above that connects normally closed to common flips over to connect normally open and common.

Assembly

Onto the assembly. First, I'm using a BlackBoard for it's Qwiic capabilities and it's powered via micro-USB. I have a button plugged into a breadboard, straddling the gap in the center, and jumper wires connecting it to pin 2 and GND on the blackboard.

BlackBoard with Button and Qwiic Cable

On the tail end is a Qwiic connector leading to the Quad Relay.

Let's take a quick look at the lamp wire, before we look at the Quad Relay. Our goal here is to sever one of the two lamp wires, and plug the two ends of the cut wire into the relay which will reconnect the wire when we activate the switching mechanism. First, I've cut one of the two wires as shown to create a break in the connection.

Cutting Cable

I then peeled the wire apart and stripped the two ends.

Strip Wire Ends

We'll put one end of our wire in the COM channel, and the other we'll have to decide upon. For this project we want our switch to act intuitively: when you activate the switching mechanism, the light switches on. There could be a case where you want the switching mechanism activated as its "rest" state. Since we're going with a more normal approach we'll cut our wire and place one end in common and the other in the normally open channel. Now when we activate the switching mechanism, the severed wire will be reconnected when the switch flips to the normally open channel connecting it and the common channel.

For the quad relay, I'm powering the 5V system (the relays), with a 5V Wall Adapter, and the 5V Wall Adapter jumper closed underneath. The Qwiic cable from the black board is providing power to the 3.3V system as seen at the top of the picture below, and we have the lamp cable plugged into and the screw terminals tightened down on channels COM and NO.

Connection on Qwiic Quad Relay Side

Now that our hardware is all set up, let's take a look at the code that turns the lamp on. Remember to not touch the relay's contacts when the system is powered.

Arduino Library

We've written a library to make it even easier to get started with the SparkFun Qwiic Quad Relay. The library will give you the full functionality of the Qwiic Quad Relay without the hub bub of the I²C data transactions. You can click the link below to download the file or navigate through the Arduino Library Manager by searching SparkFun Qwiic Relay. You can also go the Github page and get it directly.

This library also works with our Qwiic Single Relay board. If you only need one relay then go check it out!

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

Library Functions Overview

The list below outlines all of the functions of the Qwiic Relay Arduino Library designed to work with the Qwiic Quad Relay along with short descriptions of what they do. The examples cover nearly all of the functions so take a look at those for demonstrations on how to integrate them into your own code.

  • bool begin(TwoWire &wirePort = Wire); - Initialize the Qwiic Relay on the I2C bus
  • float singleRelayVersion(); - Returns the version number of the relay
  • void turnRelayOn(uint8_t relay); - Turn the given relay on. Valid inputs for relay are 1 through 4. For example, turnRelayOn(1); will toggle the first relay.
  • void turnRelayOff(uint8_t relay); - Turn the selected relay off. Similar to the above function, select values between 1 and 4 to turn the chosen relay off.
  • void toggleRelay(uint8_relay) - Toggles the selected relay to the opposite state. The function first checks the status of the relay and is toggled to either on or off depending on what the status check returns.
  • void turnAllRelaysOn(); - Turns all relays on the board on.
  • void turnAllRelaysOff(); - Turns all relays on the board off.
  • void toggleAllRelays(); - Toggles all relays on the board to the opposite state of the relay status check.
  • uint8_t getState(uint8_t relay); - Returns the status of the selected relay. Returns 1 if on or 0 if off. Just like with previous functions, valid inputs for relay are 1 through 4.
  • bool changeAddress(uint8_t newAddress); - Changes the I2C address of the Qwiic Relay. The new address is written to the memory location in EEPROM that determines the address. Valid newAddress values can be between 0x07 and 0x78.

Example Code

Example 4 - Relay Control using Buttons

This is the code used for the lamp example below. Unzip and open up example four under ... > SparkFun Qwiic_Relay_Arduino Library-master > Example Code > Example4_Quad_Relay_Buttons to follow along. Starting at the top, we have #include-ed the path to the library's header file as well as to Arduino's I²C library: Wire.h. To use the functions in the SparkFun Qwiic Relay Library we create a version of it, and name it quadRelay. You'll notice that in parentheses we have given it the board's address. If you have changed it or closed the address jumper, than change the RELAY_ADDR to your address.

language:c
#include <Wire.h>
#include "SparkFun_Qwiic_Relay.h"

#define RELAY_ADDR 0x6D

Qwiic_Relay quadRelay(RELAY_ADDR);

Next we setup three buttons: yellow, red, and blue on three pins: 2, 3, and 4.

language:c
const int yellow_btn = 2;
const int red_btn    = 3;
const int blue_btn   = 4;

First we check that we can communicate correctly with the Quad Relay with the quadRelay.begin() function call. If there are some connection issues we'll find out about them here. Notice that his won't stop our code from running so keep an eye out for an error message. Next we use pullup resistors on our buttons to put them into a known HIGH state.

language:c
void setup()
{
  Wire.begin(); 
  Serial.begin(115200);

  if(!quadRelay.begin())
    Serial.println("Check connections to Qwiic Relay.");
  else
    Serial.println("Ready to flip some switches.");

    //Use internal resitors to keep them in a known high state. 
  pinMode(yellow_btn, INPUT_PULLUP);
  pinMode(blue_btn, INPUT_PULLUP);
  pinMode(red_btn, INPUT_PULLUP);

}

Finally in the loop the buttons are constantly being checked for a button press. For example, if the blue button is pressed then relay number one turns on. The small 400ms delay is there for debounce. Without it each of our casual presses would be read a couple hundred times before we finally took our finger off of the button.

language:c
void loop()
{
    // Button one turns on relay one....
  if(digitalRead(yellow_btn) == LOW){
        delay(400);
    quadRelay.turnRelayOn(1);
    Serial.println("Yellow Button");
  }

    // Button two turns on relay two....
  if(digitalRead(blue_btn) == LOW){
        delay(400);
    quadRelay.turnRelayOn(2);
    Serial.println("Blue Button");
  }

  // Button three turns off relay one and two...
  if(digitalRead(red_btn) == LOW){
        delay(400);
    quadRelay.turnRelayOff(1);
    quadRelay.turnRelayOff(2);
    Serial.println("Red Button");
  }

}

Now let's upload some code via the Arudino IDE. Before uploading, be sure to remove power to the load when uploading to safely handle the relay. Then connect the Arduino to your computer to upload. Select the board (in this case the Arduino/Genuino Uno) and COM port that your Arduino has enumerated to. Click the upload button. When the code has finished uploading, place the Arduino and relay on a non-conductive surface to test. Remember to not touch the relay's contacts when the system is powered.

Let There Be Light!

After we load up the code, and press the button we should see the relay one LED light up.

Qwiic Quad Relay Powered

If your relay LED is on and the lamp doesn't turn on, make sure you have the lamp turned on. We'll let the relay handle turning it off and on from now on. Now if all is correctly assembled:

Quad Relay in Action

Algebraic!!

Resources and Going Further

Now that you've successfully got your SparkFun Qwiic Quad Relay up and running, it's time to incorporate it into your own project!

For more information, check out the resources below:

Need some inspiration for your next project? Check out some of these other awesome related tutorials using relays. Be sure to check your current rating when handling the Qwiic Single Relay when browsing some of the other tutorials using relays.

Photon Remote Water Level Sensor

Learn how to build a remote water level sensor for a water storage tank and how to automate a pump based off the readings!

Blynk Board Project Guide

A series of Blynk projects you can set up on the Blynk Board without ever re-programming it.

ESP8266 Powered Propane Poofer

Learn how Nick Poole built a WiFi controlled fire-cannon using the ESP8266 Thing Dev Board!

Blynk Board Bridge Widget Demo

A Blynk project that demonstrates how to use the Bridge widget to get two (or more) Blynk Boards to communicate.

Beefcake Relay Control Hookup Guide

This is a guide for assembling and basic use of the Beefcake Relay Control board

How to Build a Remote Kill Switch

Learn how to build a wireless controller to kill power when things go... sentient.

IoT Power Relay

Using the ESP32 to make a web-configured timed relay.

Qwiic Single Relay Hookup Guide

Get started switching those higher power loads around with the Qwiic Single Relay.

Or check out these blog posts for inspiration.