Qwiic Single Relay Hookup Guide

Pages
Contributors: Englandsaurus
Favorited Favorite 3

Arduino Library

We've written a library to make it even easier to get started with the SparkFun Qwiic Single Relay. The library will give you the full functionality of the Qwiic Single 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 Quad Relay board. If you need more relays on one PCB, 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 the functions of the Qwiic Relay Arduino Library designed to work with the Qwiic Single Relay along with short descriptions of what they do. The examples cover nearly all of these functions so take a look at them for help integrating them into your own code.

  • bool begin(TwoWire &wirePort = Wire); - Initialize the Qwiic Single Relay on the I2C bus
  • float singleRelayVersion(); - Returns the firmware version present on the Qwiic Single Relay.
  • void turnRelayOn(); - Turn the relay on.
  • void turnRelayOff(); - Turn the relay off.
  • void toggleRelay() - Toggles the 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.
  • uint8_t getState(); - Returns the status of the relay. Returns 1 if on or 0 if off.
  • bool changeAddress(uint8_t newAddress); - Changes the I2C address of the Qwiic Relay to the value set for newAddress. Valid newAddress values can be between 0x07 and 0x78. The new address is written to the memory location in EEPROM that determines the address.