Skip to content

Commit 5fd49dc

Browse files
committed
Update cloud-relay-control.md
1 parent 4becf18 commit 5fd49dc

File tree

1 file changed

+47
-143
lines changed

1 file changed

+47
-143
lines changed

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

Lines changed: 47 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -34,183 +34,87 @@ The goals of this project are:
3434

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

37-
## Step 1: Setting up the Arduino IoT Cloud
37+
## Overview
3838

39-
To do so, we will first need to configure our MKR 1010 device in the Arduino IoT Cloud. Let's start by navigating to the <a href="https://create.arduino.cc/iot/" target="_blank">Arduino IoT Cloud</a>.
39+
In this guide we will:
40+
- Configure a manual device in the Arduino Cloud,
41+
- install the Arduino IoT Cloud Python library,
42+
- write a Python script that connects to the Arduino Cloud.
4043

41-
>**Note:** You will need a Arduino account to use the Arduino IoT Cloud. If you do not have one, you will be directed to the account registration.
44+
## Requirements
4245

43-
### Configure a new device
46+
To follow this guide, make sure to have:
4447

45-
Once we are in the Arduino IoT Cloud, we will need to click on the **"Devices"** tab. This will open a new page which will ask you to add a new device. Click on the **"Add device"** button.
48+
- An [Arduino account](https://login.arduino.cc/login),
49+
- a version of [Python](https://www.python.org/downloads/) installed,
50+
- [pip](https://packaging.python.org/en/latest/tutorials/installing-packages/) package manager installed,
51+
- [Arduino IoT Python Client](https://pypi.org/project/arduino-iot-client/) installed.
52+
- A code editor (we recommend [VSCode](https://code.visualstudio.com/) with the Python extension installed).
4653

47-
![Adding a new device.](assets/new_device.png)
54+
***The experience with Python and the `pip` package mangager varies depending on your computer and operating system. Python needs to be in your PATH to use the Arduino IoT Cloud Python client.***
4855

49-
You will now have an option of either configuring a new Arduino device, or a third party device. Select the **"Set up an Arduino device** option.
56+
## Cloud Setup
5057

51-
![Selecting the type of device.](assets/device_setup_1.png)
58+
To set up the Arduino Cloud, follow the steps below. In there, we will
59+
- create and configure a device,
60+
- create a Thing,
61+
- create cloud variables.
5262

53-
At this point, you will need to connect your cloud compatible board to your computer. You will also need to have installed the Arduino Create Agent. If if it is not installed, the set up wizard will ask you to install it. Your device should now show up, and you will need to click on the **"Configure"**
54-
button.
5563

56-
![Device found.](assets/device_setup_2.png)
64+
### Device Configuration
5765

58-
You will now be asked to name your device. In this case, a name was randomly generated, which is **Phil**. Click on **"Next"** to proceed.
66+
To configure a device, navigate to the [app.arduino.cc/devices](app.arduino.cc/devices) and click on the **"create a new device"** button. Connect your board to your computer, and make sure you have the [Create Agent](https://create.arduino.cc/getting-started/plugin/welcome) installed. Your board will appear, and the installation takes a couple of minutes.
5967

60-
![Naming the device.](assets/device_setup_3.png)
68+
***Learn more about Devices in the [Devices documentation]().***
6169

62-
After clicking on next, the board will start to configure. This process may take a few minutes.
70+
### Thing Configuration
6371

64-
![The configuration process.](assets/device_setup_4.png)
72+
1. Create a new Thing, by clicking on the **"Create Thing"** button.
73+
2. Click on the **"Select Device"** in the **"Associated Devices"** section of your Thing. Your previously configured device will appear from the list.
74+
3. In the network section, enter your network credentials.
6575

66-
Once it is done, we will be directed to the devices page, where we can see our device. Congratulations, you have just made your first device IoT ready!
76+
***Learn more about Things in the [Things documentation]().***
6777

68-
![Configuration complete!](assets/device_overview.png)
78+
### Create Variables
6979

70-
### Creating a Thing and linking your device
80+
Next step is to create some cloud variables, which we will later sync with our Arduino MKR WiFi 1010 board.
7181

72-
After our device is configured, we can move on to the next step: creating our very first Thing. Click on the **"Things"** tab. You should now see a button that says **"Create thing"**, which we will need to click.
82+
While in Thing configuration, click on **"Add Variable"** which will open a new window. Add the following variables with the specified configurations:
7383

74-
![Creating a thing.](assets/new_thing.png)
84+
| Variable Name | Data Type | Permission |
85+
| ------------- | --------- | ------------ |
86+
| `relay_1` | Boolean | Read & Write |
87+
| `relay_2` | Boolean | Read & Write |
7588

76-
We will now see an interface with multiple options. This is your Thing configuration overview. Here we can select what network we are connecting to, what device we are using and create variables that we want to sync.
89+
Your Thing interface should now look something like this:
7790

78-
![Overview of a Thing.](assets/thing_overview.png)
91+
![]()
7992

80-
Let's start by linking our freshly configured device, by clicking on the **"Select Device"** button to the right. This will open up a window, where we can **"Associate"** the board with this Thing.
93+
***Need help understanding cloud variables? Check out the [Variables]() section.***
8194

82-
![Associating the device.](assets/associate_device.png)
95+
### Create Sketch
8396

84-
### Creating variables
85-
86-
Now, we can continue to create **variables** for our Thing. These variables will be synced with the cloud, as long as the board is connected to Internet and the cloud.
87-
88-
For this application, we will create two **boolean** variables: one for each relay on the MKR Relay Shield.
89-
90-
To create a new variable, click on the **"Add Variable"** button.
91-
92-
![The "Add Variable" button.](assets/cloud-relay-control-img01.png)
93-
94-
Let's name it **relay_1**, and select the **boolean** data type. Then click on **"Add Variable"**.
95-
96-
![Adding the first variable.](assets/cloud-relay-control-img02.png)
97-
98-
Let's add another variable, but let's name this one **relay_2**, which is also a boolean variable.
99-
100-
![Adding the second variable.](assets/cloud-relay-control-img03.png)
101-
102-
Great, now we have two **boolean variables** named **relay_1** and **relay_2**.
103-
104-
### Adding your network details
105-
106-
Now that we have created the variables, we can configure the **network details**. This is done by clicking on the **"Configure"** button in the **"Network"** section.
107-
108-
![Entering network details.](assets/cloud-relay-control-img04.png)
109-
110-
>**Note:** You can't enter any network details until you have added a variable.
111-
112-
113-
### Over the Air Uploads
114-
115-
Did you know that the Arduino IoT Cloud supports over the air uploads? When you've uploaded a sketch to your board once, it will become available for you to upload a new sketch to the board without connecting it to your computer!
116-
117-
***Over the Air uploads require an Entry plan to the Arduino IoT Cloud***
118-
119-
120-
To use this feature, make sure the board has power. If your board is already connected to the IoT Cloud, you will be able to upload to it over the air. Navigate to the Things sketch tab in the Arduino IoT Cloud interface, and you should see it being discovered just as if it was connected via USB.
121-
122-
123-
### Creating the program
124-
125-
Once we are finished with all the configurations, we can move on to creating the sketch that we are going to upload to our MKR WiFi 1010. To do so, we first need to go to the **"Sketch"** tab.
126-
127-
![Open the "Sketch" tab to edit the sketch.](assets/cloud-relay-control-img05.png)
128-
129-
The sketch we are going to create is very simple. As most of the code is already generated through the configurations we made, we only need to make a few additions: configuring the relay pins as output, and creating two conditionals.
130-
131-
You can find the full sketch below, which we need to upload to our board.
97+
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:
13298

13399
```arduino
134-
#include "thingProperties.h"
135-
136-
void setup() {
137-
// Initialize serial and wait for port to open:
138-
Serial.begin(9600);
139-
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
140-
delay(1500);
141-
142-
pinMode(1, OUTPUT);
143-
pinMode(2, OUTPUT);
144-
145-
// Defined in thingProperties.h
146-
initProperties();
147-
148-
// Connect to Arduino IoT Cloud
149-
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
150-
151-
/*
152-
The following function allows you to obtain more information
153-
related to the state of network and IoT Cloud connection and errors
154-
the higher number the more granular information you’ll get.
155-
The default is 0 (only errors).
156-
Maximum is 4
157-
*/
158-
setDebugMessageLevel(2);
159-
ArduinoCloud.printDebugInfo();
160-
}
161-
162-
void loop() {
163-
ArduinoCloud.update();
164-
// Your code here
165-
166-
}
167-
168-
void onRelay1Change() {
169-
// Do something
170-
if(relay_1){
171-
digitalWrite(1, LOW);
172-
}
173-
else{
174-
digitalWrite(1, HIGH);
175-
}
176-
}
177-
178-
void onRelay2Change() {
179-
// Do something
180-
if(relay_2){
181-
digitalWrite(2, LOW);
182-
}
183-
else{
184-
digitalWrite(2, HIGH);
185-
}
186-
}
187-
```
188-
189-
## Step 2: Creating a dashboard
190-
191-
After our code has been successfully uploaded to our board, we we will need to create a dashboard to control our relays!
192100
193-
Head over to the **"Dashboards"** tab, and click on **"Build Dashboard"**.
194-
195-
![Click on "Build a dashboard".](assets/cloud-relay-control-img06.png)
196-
197-
We can now see an empty dashboard. Let's click on the **"Add"** button, and select a **Switch** widget.
101+
```
198102

199-
![Adding a switch widget.](assets/cloud-relay-control-img07.png)
103+
Upload this sketch to your board, and your board will start attempting to connect to the Arduino Cloud and sync its data.
200104

201-
Now, we need to link it with our **relay_1** variable, inside our Thing.
105+
You can verify that your device is connecting properly, by checking the Serial Monitor just after connection. Error codes are printed here.
202106

203-
![Linking a variable to the widget.](assets/cloud-relay-control-img08.png)
107+
### Create a Dashboard
204108

205-
We also need to rename the widget so we know which one is which. We choose **"RELAY_1"**.
109+
Once you have your device running a sketch and syncing with the Arduino Cloud, you can create a **dashboard**, a visualization tool for monitoring & interacting with your board.
206110

207-
![Naming the widget.](assets/cloud-relay-control-img09.png)
111+
Navigate to [app.arduino.cc/dashboard](app.arduino.cc/dashboard) and create a dashboard. Add two switches (or any other preferred widgets), and link them to each `relay_x` variable that we created earlier. These switches will be directly linked with your Arduino MKR WiFi 1010's variables, and will turn ON/OFF the relays on your board.
208112

209-
Now, repeat the same process, but instead link it to the **relay_2** variable. At the end, we should have two widgets, each linked to a relay.
113+
You can also access your dashboard via the [Arduino IoT Remote app]().
210114

211-
![The complete dashboard.](assets/cloud-relay-control-img10.png)
115+
![Interact with your board]()
212116

213-
Now you can simply test it out by turning ON or OFF the switches. You should hear the relays on your **MKR Relay Shield** making clicking noises. That means it is working!
117+
***For more information on dashboards, available widgets and how to link them to your sketch, visit the [Dashboard & Widgets]() section.***
214118

215119
## Step 3: Connecting a component with higher voltage
216120

0 commit comments

Comments
 (0)