
⚡
Warning!
Make sure that your wires connecting to the wall outlet are secure and are rated to handle the
current! Please be careful when handling the contacts when the cable is plugged into a wall outlet.
Touching
the contacts while powered could result in injury.
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.
Example Code
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.
Let’s take a look at some example code fort the Qwiic Quad Relay. You can download all example codes from the
GitHub repo by clicking the link below.
QWIIC QUAD RELAY EXAMPLE CODE (ZIP)
Example 1 - Relay Control
This is the code used for the lamp example above. Unzip and open up example one under
…
>
Qwiic_Quad_Relay-master
>
Example Code
>
Example1_Relay_Control
to follow along. At the top, let’s break
down the defines that are provided. While all of them might not be necessary for your project and they weren’t for
the lamp example, they are still displayed here to elucidate the functionality of the Quad Relay. First the default
address
0x6D
is included and it’s followed by the second I C address
0x6C
, which is commented out. If you’d
rather use the latter then close the jumper on the underside of the product labeled
ADDR
.
#include <Wire.h>
#define RELAY_ADDR 0x6D // Default address - open jumper.
//#define RELAY_ADDR 0x6C // Address when jumper is closed.
2