Skip to content

Commit 1f9392e

Browse files
committed
cloud relay
1 parent 53ba99b commit 1f9392e

File tree

3 files changed

+73
-20
lines changed

3 files changed

+73
-20
lines changed
97.5 KB
Loading
79.6 KB
Loading

content/arduino-cloud/11.application-notes/cloud-relay-control/cloud-relay-control.md

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
2-
title: 'Controlling relays from the Arduino IoT Cloud'
3-
compatible-products: [mkr-wifi-1010, mkr-proto-relay-shield]
4-
difficulty: beginner
2+
title: 'Remote Relay Control'
53
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]
85
author: 'Karl Söderby'
96
---
107

118
## Introduction
129

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.***
1413

1514
## Goals
1615

@@ -34,23 +33,14 @@ The goals of this project are:
3433

3534
![Mount the board on top of the shield.](assets/cloud-relay-control-circuit.png)
3635

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-
4836
## Cloud Setup
4937

5038
To set up the Arduino Cloud, follow the steps below. In there, we will
5139
- create and configure a device,
5240
- 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.
5444

5545
### Device Configuration
5646

@@ -88,7 +78,59 @@ Your Thing interface should now look something like this:
8878
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:
8979

9080
```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
87+
delay(1500);
88+
89+
pinMode(1, OUTPUT);
90+
pinMode(2, OUTPUT);
91+
92+
// Defined in thingProperties.h
93+
initProperties();
94+
95+
// Connect to Arduino IoT Cloud
96+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
97+
98+
/*
99+
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+
}
92134
```
93135

94136
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:
135177
digitalWrite(relay_1, HIGH)
136178
```
137179

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

Comments
 (0)