SparkFun Qwiic Dual Solid State Relay Hookup Guide
Qwiic Relay Arduino Library
The SparkFun Qwiic Relay Arduino Library works with all SparkFun Qwiic Relay boards to help you use your Qwiic Relay to its full functionality. 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.
Library Functions
The list below outlines all of the functions of the Qwiic Relay library along with short descriptions of what they do. The examples cover nearly all of the functions so we recommend referring to them for help integrating the functions into your own code.
These functions will work with all SparkFun Qwiic Relay boards.
bool begin(TwoWire &wirePort = Wire);
- Initialize the Qwiic Relay on the I2C busfloat singleRelayVersion();
- Returns the version number of the firmware present on your relay board.void turnRelayOn(uint8_t relay);
- Turn the given relay on. 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.uint8_t getState(uint8_t relay);
- Returns the status of the selected relay. Returns1
if on or0
if off.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.
The below function is intended for the Qwiic Solid State Relay boards only. It will not work on either of the Qwiic Mechanical Relay boards.
bool setSlowPWM(uint8_t relay, uint8_t pwmValue);
- Starts a slow PWM (1Hz) with a range from 0-120 for the selected relay. The PWM range is limited to 0-120 as this is the maximum PWM resolution for Zero-crossing SSR's at 60Hz. SettingpwmValue
to 120 will give you 100% duty cycle and continuously keep the selected relay switched on.