You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'Learn how to control the relays onboard the MKR Relay Shield through the Arduino IoT Cloud dashboard.'
6
-
tags:
7
-
- Relays
4
+
tags: [Relays, 24V]
8
5
author: 'Karl Söderby'
9
6
---
10
7
11
8
## Introduction
12
9
13
-
In this tutorial, we will go through how to control a MKR WiFi 1010 + a MKR Relay shield from the [Arduino IoT Cloud](https://create.arduino.cc/iot/things). We will create a simple configuration that allows us activate each of the relays on the shield through a dashboard in the cloud.
10
+
This tutorial demonstrates how to use a MKR WiFi 1010 and a MKR Relay shield with the [Arduino Cloud](app.arduino.cc). We will create a simple configuration that allows us activate the relays on the shield through a dashboard.
11
+
12
+
***You can easily change the board and shield for another setup, as long as the board is supported by the Arduino Cloud.***
14
13
15
14
## Goals
16
15
@@ -34,23 +33,14 @@ The goals of this project are:
34
33
35
34

36
35
37
-
## Overview
38
-
39
-
In this guide we will:
40
-
-
41
-
42
-
## Requirements
43
-
44
-
To follow this guide, make sure to have:
45
-
46
-
- An [Arduino account](https://login.arduino.cc/login),
47
-
48
36
## Cloud Setup
49
37
50
38
To set up the Arduino Cloud, follow the steps below. In there, we will
51
39
- create and configure a device,
52
40
- create a Thing,
53
-
- create cloud variables.
41
+
- create cloud variables,
42
+
- upload a program to the MKR WiFi 1010 board,
43
+
- create a dashboard.
54
44
55
45
### Device Configuration
56
46
@@ -88,7 +78,59 @@ Your Thing interface should now look something like this:
88
78
After your device & Thing is configured, you can program your board. Navigate to the **"Sketch"** tab inside your Thing, where you can compile & upload your programs. You will find the sketch for this application in the code snippet below:
89
79
90
80
```arduino
91
-
81
+
#include "thingProperties.h"
82
+
83
+
void setup() {
84
+
// Initialize serial and wait for port to open:
85
+
Serial.begin(9600);
86
+
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
The following function allows you to obtain more information
100
+
related to the state of network and IoT Cloud connection and errors
101
+
the higher number the more granular information you’ll get.
102
+
The default is 0 (only errors).
103
+
Maximum is 4
104
+
*/
105
+
setDebugMessageLevel(2);
106
+
ArduinoCloud.printDebugInfo();
107
+
}
108
+
109
+
void loop() {
110
+
ArduinoCloud.update();
111
+
// Your code here
112
+
113
+
}
114
+
115
+
void onRelay1Change() {
116
+
// Do something
117
+
if(relay_1){
118
+
digitalWrite(1, LOW);
119
+
}
120
+
else{
121
+
digitalWrite(1, HIGH);
122
+
}
123
+
}
124
+
125
+
void onRelay2Change() {
126
+
// Do something
127
+
if(relay_2){
128
+
digitalWrite(2, LOW);
129
+
}
130
+
else{
131
+
digitalWrite(2, HIGH);
132
+
}
133
+
}
92
134
```
93
135
94
136
Upload this sketch to your board, and your board will start attempting to connect to the Arduino Cloud and sync its data.
@@ -135,4 +177,15 @@ To de-activate the relays:
135
177
digitalWrite(relay_1, HIGH)
136
178
```
137
179
138
-
>**Note:** Use extreme caution when creating higher power circuits. Make sure that both the power supply and the component does not exceed 24V. For example, connecting it straight to a wall socket without a power converter would supply 220-240V, which is **10 times as high.**
180
+
>**Note:** Use extreme caution when creating higher power circuits. Make sure that both the power supply and the component does not exceed 24V, as the relays are not designed to handle higher voltages.
181
+
182
+
## Use Cases
183
+
184
+
Relays can be used for practically any project that needs to switch on and off circuits. Typically, relays can be used to control:
185
+
- LED strips
186
+
- Fans
187
+
- Pumps
188
+
- Low power heating elements
189
+
- Low power fridges
190
+
191
+
12/24V systems are also frequent in cars, boats & remote setups where a system might be powered by a 12/24V battery.
0 commit comments