Qwiic Quad Relay Hookup Guide
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!
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.
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.
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.
Suggested Reading
If you aren't familiar with the Qwiic system, we recommend reading here for an overview.
Qwiic Connect System |
We would also recommend taking a look at the following tutorials if you aren't familiar with them.
Serial Communication
Hardware Overview
- 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.
4
.v2.0 | v1.0 |
Power
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
I then peeled the wire apart and stripped the two 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.
Looking for information about safety and insulation? Check out the notes about Safety and Insulation from our Beefcake Relay Control Kit.
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!
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 busfloat singleRelayVersion();
- Returns the version number of the relayvoid turnRelayOn(uint8_t relay);
- Turn the given relay on. Valid inputs forrelay
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 eitheron
oroff
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. Returns1
if on or0
if off. Just like with previous functions, valid inputs forrelay
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. ValidnewAddress
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.
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:
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:
- Schematic (PDF) - v2.0
- Eagle Files (ZIP) - v2.0
- Board Dimensions (PNG) - v2.0
- Datasheet (PDF)
- SparkFun Qwiic Relay Arduino Library Github Repo
- SparkFun Qwiic Relay Python Package GitHub Repo
- GitHub Repo
- SFE Product Showcase
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
Blynk Board Project Guide
ESP8266 Powered Propane Poofer
Blynk Board Bridge Widget Demo
Beefcake Relay Control Hookup Guide
How to Build a Remote Kill Switch
Qwiic Single Relay Hookup Guide
Or check out these blog posts for inspiration.