Qwiic Quad Relay Hookup Guide

Pages
Contributors: Elias The Sparkiest
Favorited Favorite 4

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.