© Agus Kurniawan  2021
A. KurniawanBeginning Arduino Nano 33 IoThttps://doi.org/10.1007/978-1-4842-6446-1_5

5. Arduino IoT Cloud

Agus Kurniawan1  
(1)
Faculty of Computer Science, Universitas Indonesia, Depok, Indonesia
 

Arduino IoT Cloud is one of Arduino services to provide a cloud service for an IoT platform. We can send and receive data from IoT devices to Arduino IoT Cloud. This chapter explores how Arduino Nano 33 IoT interacts with Arduino IoT Cloud.

You will learn the following topics in this chapter:
  • Setting up Arduino IoT Cloud

  • Building programs on Arduino Nano 33 IoT for the Arduino IoT Cloud

  • Building sensor monitoring program with the Arduino IoT Cloud

Introduction

A cloud technology enables us to enhance our IT and business productivity. A cloud technology also can be used to address IoT solutions. Arduino IoT Cloud is one of cloud servers from Arduino. We can send and receive data from Arduino IoT Cloud to our Arduino devices.

In this chapter, we build programs on Arduino Nano 33 IoT to access the Arduino IoT Cloud. Arduino Nano 33 IoT has a WiFi module so we can connect to the Arduino IoT cloud over the WiFi network. Make sure you have Internet access on WiFi network.

Setting up Arduino IoT Cloud

To access and build programs for the Arduino IoT Cloud, we need to set up our Arduino devices. We should register a new account to this platform. You can register your account on Arduino IoT Cloud to this link, https://create.arduino.cc/iot/. After we sign up, we register our Arduino Nano 33 IoT to the Arduino IoT Cloud.

You can see the Arduino IoT Cloud dashboard in Figure 5-1. We have three menus: Things, Dashboards and Devices. Members without a paid subscription can only create the Things menu on this platform.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig1_HTML.jpg
Figure 5-1

A dashboard of the Arduino IoT Cloud website

If you have an account in the Arduino store, you can use the same account to sign up for Arduino IoT Cloud. Then, we can register our Arduino Nano 33 IoT.

Register Arduino Nano 33 IoT

Before we use Arduino IoT Cloud, we have to register our Arduino devices. In this chapter, we use Arduino Nano 33 IoT. We have some steps to register our Arduino devices. You can perform the following tasks:
  • installing Arduino Create Agent

  • adding a new Arduino device

Next, we can install the Arduino Create Agent.

Install the Arduino Create Agent

Arduino Create Agent is a background program to listen to our local Arduino devices. This agent program acts as a bridge between local Arduino devices and Arduino IoT Cloud.

The Arduino Create Agent program is available for Windows, Linux, and the macOS platform. You can download this program at this link, https://github.com/arduino/arduino-create-agent. After installed, you should allow this program to run in the background. On the Windows platform, you can see a tray icon for the Arduino Create Agent on the taskbar, as shown in Figure 5-2.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig2_HTML.jpg
Figure 5-2

A tray icon of the Arduino Create Agent on Windows OS

You can open the Debug Console menu by clicking this in the Arduino Create Agent. If your Arduino devices are attached on local computer, a debug console from the Arduino Create Agent will show our device status. Figure 5-3 shows my Arduino Nano 33 IoT is detected.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig3_HTML.jpg
Figure 5-3

A form of the Arduino Create Agent Debug Console

If you don’t see your Arduino device, make sure your Arduino is attached to your computer properly. After completed, you can register your Arduino Nano 33 IoT.

Add New Arduino Device

Once we have set up the Arduino Create Agent program on a local computer, we can add a new Arduino device. You can open the Arduino IoT Cloud website. Then, click the DEVICES menu. You can see a list of Arduino devices.

Now you can add a new Arduino Nano 33 IoT. You can plug in your Arduino Nano 33 IoT. You should see a dialog, as shown in Figure 5-4. Click Set up in the Arduino device menu.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig4_HTML.jpg
Figure 5-4

Adding a new Arduino device

After clicking this option, you should see Arduino Nano 33 IoT, as shown in Figure 5-5. If you don’t see your Arduino Nano 33 IoT, make sure your Arduino Nano 33 IoT is attached and Arduino Create Agent is running.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig5_HTML.jpg
Figure 5-5

Arduino IoT Cloud detected Arduino Nano 33 IoT

Set your device name for Arduino Nano 33 IoT. If done, you can click the CONFIGURE button. Arduino IoT Cloud will configure your Arduino Nano 33 IoT, as shown in Figure 5-6. It will take several minutes to complete this task. After completing configuration , you should see your Arduino Nano 33 IoT listed on the Arduino IoT Cloud list, as shown in Figure 5-7.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig6_HTML.jpg
Figure 5-6

Configuring Arduino Nano 33 IoT

../images/502248_1_En_5_Chapter/502248_1_En_5_Fig7_HTML.jpg
Figure 5-7

Arduino Nano 33 IoT device was added

Develop a Remote LED Button

In this section, we build a program to remote LED from the Arduino IoT Cloud dashboard. We can turn on/off the LED on Arduino Nano 33 IoT from the Arduino IoT Cloud dashboard website.

To implement our demo, we can perform some tasks with the following steps:
  • adding a new thing

  • adding properties

  • editing Sketch program

  • building a dashboard

  • testing

We implement these steps in the next section.

Adding a New Thing

A feature of the Arduino IoT Cloud is a program to interact with Arduino devices. With a free membership, we can only create one thing. In this demo, we build a remote for the LED from the Arduino IoT Cloud dashboard.

Open the Arduino IoT Cloud website. Click the Things menu. Then, you can obtain a form, as shown in Figure 5-8. Enter your Thing name and Arduino device. Each Thing is connected by one Arduino device.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig8_HTML.jpg
Figure 5-8

Adding a new Thing

After you set the Thing name, you can click the CREATE button. After that, you will see a form, as shown in Figure 5-9. We will configure Properties for Arduino Nano 33 IoT in the next section.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig9_HTML.jpg
Figure 5-9

A dashboard of an Arduino Thing

Adding a Property

We can expose I/O from Arduino Nano 33 IoT through the Thing property. For instance, we want to expose sensor data to the Arduino IoT Cloud. In this scenario, we want to expose our built-in LED in Arduino Nano 33 IoT. We can set I/O on LED so we can turn on/off the LED over the web.

You can start by opening a Thing on the Arduino IoT Cloud. Figure 5-9 shows our Thing that we already created. Click the Add Property button to add a new property. After clicking, you will obtain a form, as shown in Figure 5-10.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig10_HTML.jpg
Figure 5-10

Adding a new property

In this scenario, you can set the following options:
  • Name: LED1

  • VARIABLE NAME: lED1

  • TYPE: ON/OFF (Boolean)

  • Permission: Read & Write

  • Update: when the value changes

  • History: checked

My entry is shown in Figure 5-10. After filled all fields, you can click the ADD PROPERTY button. You will come back to the Things form. You should see LED1 property on the Thing form, as shown in Figure 5-11.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig11_HTML.jpg
Figure 5-11

A Thing with one property

You have created a Thing. Next, we can modify the Sketch program in order to connect to this LED1 property.

Editing the Sketch Program

Now we can edit our Sketch program. On the property form from the Thing dashboard (see Figure 5-11), you can click the EDIT SKETCH button. After clicking, you will obtain the Arduino web editor, as shown in Figure 5-12.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig12_HTML.jpg
Figure 5-12

Editing the Sketch program

First, we modify the Secret program to configure the WiFi network on Arduino Nano 33 IoT. Fill in SSID ID and SSID key on the Secret tab. Now we modify codes on our main Sketch.

You can see our property variable, lED1, is declared on the main Sketch program.
#include "arduino_secrets.h"
  bool lED1;
#include "thingProperties.h"
Then, we initialize our digital pin for a built-in LED. We also set lED1=false for initialization. We add the following script on the setup() function.
void setup() {
...
  lED1 = false;
  pinMode(13,OUTPUT);
....
}
On the onLED1Change() function, we perform turn on/off LED. If we have lED1=true, we turn on the LED by calling the digitalWrite() function. Otherwise, we turn off the LED.
void onLED1Change() {
  // Do something
  if(lED1)
     digitalWrite(13, HIGH);
  else
     digitalWrite(13, LOW);
}

Save this program. You can compile and upload this program to Arduino Nano 33 IoT. Click Verify and Upload icons for compiling and uploading program.

Build a Dashboard

Now we can build a dashboard that is used to create interaction between Arduino IoT Cloud and Arduino Nano 33 IoT. We can create many dashboards for a Thing project. In our scenario, we create a dashboard with a button. First, click the DASHBOARD menu. Create a new dashboard so you will obtain a form, as shown in Figure 5-13.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig13_HTML.jpg
Figure 5-13

A dashboard of Arduino IoT Cloud

We can add a new switch on our dashboard editor. Click the ADD button and select Switch widget. You can see the Switch widget option in Figure 5-14.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig14_HTML.jpg
Figure 5-14

Adding a widget on the dashboard

Click Switch widget and then drag it to the dashboard editor. After dragging the Switch widget, you should see Switch widget, as shown in Figure 5-15.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig15_HTML.jpg
Figure 5-15

Adding a switch

Click Example Data to link the Switch widget to the Thing property. After clicking, you will obtain a form as shown in Figure 5-16.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig16_HTML.jpg
Figure 5-16

Setting a Switch widget

Click the Linked Property button to link with the Thing property. We will obtain a form, as shown in Figure 5-17. Select our Thing name, and select Property (LED1). If done, click the LINK PROPERTY button. Then, we will back to our dashboard editor.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig17_HTML.jpg
Figure 5-17

Linking a switch to thing properties

You also can rename our dashboard program—for instance, LED Demo. Now we can test our dashboard program.

Testing

To test our program, we need to activate our dashboard program on running mode. You can click the USE DASHBORD button to activate the dashboard program.

You can attempt to toggle the Switch to ON mode. Then, you should see the built-in LED on Arduino Nano 33 IoT lights up. You also can turn off the LED by toggling the Switch to OFF mode.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig18_HTML.jpg
Figure 5-18

LED demo program on the dashboard editor

../images/502248_1_En_5_Chapter/502248_1_En_5_Fig19_HTML.jpg
Figure 5-19

Toggling the Switch to turn on the LED

You can customize this program by adding some LEDs. Then, you can add some properties on the Things program.

Develop Sensor Monitoring

We have created Arduino IoT Cloud to turn on/off LED on Arduino Nano 33 IoT. Now we can continue to build the Arduino IoT Cloud program for monitoring sensors. In this demo, we use built-in sensors on Arduino Nano 33 IoT. For testing, we use the Gyroscope sensor.

To implement this demo, we can perform some tasks with the following steps:
  • adding a new thing

  • adding properties

  • editing the Sketch program

  • building a dashboard

  • testing

We implement these steps in the next section.

Add a New Thing

You can create a new Thing on Arduino IoT Cloud. If you have a free membership, you should delete the existing Thing on Arduino IoT Cloud because you can only create one Thing.

Now you can create a new Thing. For instance, we set the Thing name as GyroscropeThing. Then, we can add some properties to GyroscopeThing.

Add Property

After creating a Thing, we can add properties. For this demo, we create three properties to monitor the Gyroscope sensor from Arduino Nano 33 IoT. These properties will be linked to X, Y, and Z degrees from the Gyroscope sensor. When we can add a new property, we have a form, as shown in Figure 5-20. We add three properties with property parameters as shown in Table 5-1.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig20_HTML.jpg
Figure 5-20

Adding a property on a Thing

Table 5-1

Input Paramters for Three Thing Properties

Parameters

Property 1

Property 2

Property 3

Name

xDegree

yDegree

zDegree

Variable

xDegree

yDegree

zDegree

Type

Float

Float

Float

Minimum/Maximum

-4/-4

-4/-4

-4/-4

Permission

Read-only

Read-only

Read-only

Update

   

Delta

0.05

0.05

0.05

Show history visualization

Checked

Checked

Checked

After we creat three Thing properties, we will return to our Things dashboard. You can see three properties in Figure 5-21.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig21_HTML.jpg
Figure 5-21

Three properties on GyroscopeThing

Editing the Sketch Program

After we add three properties on GyroscopeThing, we can edit the Sketch program. We will read the gyroscope sensor and then update sensor data to property variables.

Click the EDIT SKETCH button to edit our program on Arduino IoT Cloud. Then, we have the Sketch web editor. We modify this Sketch program to enable us to read the Gyroscope sensor and update three Thing properties.

First, we set the SSID ID and SSID key on Arduino Secret. Then, we open the main program. We add the LSM6DS3 library on the Sketch program.
#include "arduino_secrets.h"
#include <Arduino_LSM6DS3.h>
We will see our property variables, such as xDegree, yDegree, and zDegree.
  float xDegree;
  float yDegree;
  float zDegree;
#include "thingProperties.h"
On the setup() function, we initialize the LSM6DS3 library by calling IMU.begin() API. Then, we can access the Gyroscope sensor on Arduino Nano 33 IoT.
void setup() {
...
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }
...
}
We can read the Gyroscope sensor and then update to xDegree, yDegree, and zDegree variables. We can call IMU.gyroscopeAvailable() to check whether sensor data is available or not. To read sensor data, we can use the IMU.readGyroscope() function.
void loop() {
  ArduinoCloud.update();
  // Your code here
  if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(xDegree, yDegree, zDegree);
  }
  delay(1000);
}

Save this program. Now you can compile this Sketch program and upload to Arduino Nano 33 IoT device.

Build a Dashboard

We build a dashboard to create interaction between Arduino Nano 33 IoT and Arduino IoT Cloud. We perform a new dashboard program with the following steps:
  • Create a new dashboard.

  • Add three value widgets into the dashboard editor.

  • Each value widget is to be linked to each Thing Property, as shown in Figure 5-22.

  • Do the same action for XDegree, YDegree, and ZDegree value widgets.

Last, we can set dashboard name. Now we can test our widgets on the dashboard.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig22_HTML.jpg
Figure 5-22

Linking a property to a widget

Testing

We can test our Arduino IoT Cloud program. You can navigate to the Arduino IoT Cloud dashboard. Click the dashboard form that we already created. Click the USE DASHBORD button to be in RUN mode.
../images/502248_1_En_5_Chapter/502248_1_En_5_Fig23_HTML.jpg
Figure 5-23

Showing sensor values on the Arduino IoT Cloud dashboard

You can see the widget output in Figure 5-23. Shake your Arduino Nano 33 IoT board to see sensor data changes on dashboard widgets.

You have created a dashboard on Arduino IoT Cloud to monitor sensors from Arduino Nano 33 IoT. You can practice by applying some sensors or actuators to integrate with Arduino IoT Cloud.

Summary

We have learned how to get started with Arduino IoT Cloud. We have set up and registered our Arduino Nano 33 IoT to Arduino IoT Cloud. We also have built two programs for Arduino IoT Cloud: remoting an LED and sensor monitoring.

Next, we will learn how to work and make interaction with Bluetooth Low Energy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.150.55