Arduino IoT | IoT Platform Series #4 (Part 1)

0 1877 Easy

What is Arduino IoT Cloud?

The Arduino IoT Cloud is an online platform that makes it easy for us to create, deploy and monitor IoT projects. The platform allows anyone to create IoT projects, with a user-friendly interface, and an all-in-one solution for configuration, writing code, uploading, and visualization.

Their service allows us to configure, program and deploy our Arduino devices. An all-in-one solution for IoT development, where we can build visual dashboards to monitor and control our devices, integrate with other services, and much more.

 

Hardware components

Adafruit HUZZAH32 – ESP32 Feather Board

SparkFun Atmospheric Sensor Breakout - BME280

Software apps and online services

Arduino IoT Cloud

Arduino IDE

Arduino Web Editor

 

Get PCBs for Your Projects Manufactured

You must check out PCBWAY for ordering PCBs online for cheap!

You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop.

 

 

 

Getting Started

Arduino IoT Cloud has features that work in real-time and can be done all from a single point of contact, i.e. the Cloud. No more having to repeatedly upload the code to the Wireless Device. Upload it once, and you're good to go! But what else does it offer? Let's have a look -

Data Monitoring - Easily monitor our Arduino's sensor values through a dashboard. Using a Mobile phone or a PC.Over-The-Air (OTA) Uploads - Upload code to the connected devices over the internetWebhooks - HTTP REST APIs help us to integrate our project with any third-party service. This gives a scope to use the IoT from a broader perspectiveAmazon Alexa Support - Link the project, voice-controlled with the Amazon Alexa integration.Dashboard Sharing - Share your visualization data with other people around the world.Variable Synchronisation - Variable synchronization allows us to sync variables across devices, enabling communication between devices with minimal coding.Scheduler - Schedule any job to go on/off for a specific amount of time (seconds, minutes, hours). Basically, Automate your IoT projects and watch them work on their own on a regular routine you configure!

 

 

 

Device Setup with Arduino Cloud

It is necessary to have a development board that can be connected to the internet. Below is a list of such devices -

 ESP32/ESP9266 WiFi (Espressif)MKR 1000/1010 WiFi (Arduino)Nano RP2040 Connect (Arduino)Nano 33 IoT (Arduino)Portenta H7 (Arduino)Opta (Arduino)...and a few other boards 

We can choose between using an official Arduino board, or a board based on the ESP32 / ESP8266 SoC. The Arduino IoT Cloud currently supports connection via Wi-Fi, LoRaWAN, and mobile telecom networks.

1. Go to Arduino IoT Cloud and Sign-in with the preferred method.

2. Create a 'Thing'. The digital droplet which we will use to communicate with our device. Same as other IoT Platforms.

3. Setup the Thing - Add the variable 'temp' to store the data on the cloud. Associate a device and configure the network.

4. We will be using the device for temperature monitoring, select the variable type as 'temperature sensor'. See below -

5. Now associate a device, to set up with the ESP32 (in our case). This can be done by selecting a third-party service.

6. Make sure to save the Device ID and Secret Key of the created device. The best way would be to download the PDF which contains both the information.

7. Now configure the network. ESP32 uses wifi, and therefore enter the wifi SSID and Password.

Congratulations! The device setup is complete. We can start with writing and uploading the code.

 

 

 

Device View on Arduino Cloud - Dashboard

Since we are using the device to monitor temperature, we need to view the data on our Arduino cloud as well. Arduino IoT Cloud provides the feature 'Dashboard' to view the data pushed to the cloud from the Device.

1. Go to Arduino Dashboards. (Or even select the Dashboard tab on top)

2. Select 'Build Dashboard' and then add a widget that can view the variable 'temp' we created for our 'thing'.

3. Link the variable 'temp' to the widget.

Congratulations!! The Dashboard is ready to accept the data and view the data from the device.

 

 

 

Device Setup on Hardware - Arduino IDE

 

1. Instead of using the Web Editor, we shall be using the Arduino software itself, using the libraries to upload code to the Device for use.

 

Libraries used -

ArduinoIoTCloudArduino_ConnectionHandler

 

 

 

 

 

In Arduino IDE, Go to Tools > Manage Libraries > Search above libraries on the Library Manager.

 

2. After installation, make sure to keep the below information ready -

THING_ID - It is found in the URL section after opening the things tab.
https://create.arduino.cc/iot/things/<thing_id>/setup

DEVICE_LOGIN_NAME - It is the Device ID found in the Setup tab on the Things section. Or even the PDF file you downloaded.

DEVICE_KEY - It is the secret key that is found during device setup creation. Or even the PDF file we downloaded.

SSID & PASS - WiFi name and Password to connect the device

3. After the device info configuration, paste the below code on Arduino IDE. You can access the codes used in the project here -

CODE
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

float temp;

const char THING_ID[]           = " ";    // Thing ID of Arduino Cloud
const char DEVICE_LOGIN_NAME[]  = " ";    // Device ID of Thing
const char DEVICE_KEY[]         = " ";    // Secret device password

const char SSID[]               = " ";    // Network SSID (name)
const char PASS[]               = " ";    // Network password (use for WPA, or use as key for WEP)

void initProperties(){
  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(temp, READ, 1 * SECONDS, NULL);
}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

void setup() { 
  Serial.begin(9600);
  delay(1500); 
  initProperties();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  temp = random(20,30);
  delay(500);
}

Congratulations!! The Code is ready, you can now upload it to the Device Board.

Now that the device has been set up, we can view the data on Arduino IoT Cloud.

Visit Arduino IoT Cloud and select the dashboard you created. We can now view the device data that is pushed onto the cloud

There we go! We can now monitor the device information from Arduino's Cloud.

 

 

 

Device Control - Dashboard

Let us now see how to control our device from the Arduino Cloud Things. For this, there aren't many changes, only a few additions -

1. Go to the Things we created earlier -

2. Add the variable 'light' to store the data on the cloud, with a boolean type.

3. We will be using the device for controlling an actuator, select the variable type as 'boolean'. For digital control over the pin. See below -

Great! Now let us make a user interface for this control (dashboard)!

1. Go to Arduino Dashboards. (Or even select the Dashboard tab on top)

2. Select the created dashboard and use EDIT mode to make changes.

3. Select the 'switch' widget -

4. Link the variable 'light' to the widget -

Congratulations! Your Dashboard view is ready! ✨🎉

 

 

 

Code Changes on Hardware - Arduino IDE

Let us add the variables and functions. You can access the codes used in the project here -

CODE
bool light;
int LED = 2;
void onLightChange();

Now inside void initProperties() function, add this -

CODE
ArduinoCloud.addProperty(light, READWRITE, ON_CHANGE, onLightChange);

Inside void setup(), declare the pintype -

CODE
pinMode(LED, OUTPUT);

Now, add the below function definition to the code -

CODE
void onLightChange() {
  if(light){
    digitalWrite(LED, HIGH);
  }
  else{
    digitalWrite(LED, LOW);
  }
}

The compiled code should look like this -

CODE
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

float temp;
bool light;
int LED = 2;
void onLightChange();

const char THING_ID[]           = " ";    // Thing ID of Arduino Cloud
const char DEVICE_LOGIN_NAME[]  = " ";    // Device ID of Thing
const char DEVICE_KEY[]         = " ";    // Secret device password

const char SSID[]               = " ";    // Network SSID (name)
const char PASS[]               = " ";    // Network password (use for WPA, or use as key for WEP)

void initProperties(){
  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(temp, READ, 1 * SECONDS, NULL);
  ArduinoCloud.addProperty(light, READWRITE, ON_CHANGE, onLightChange);
}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

void setup() { 
  pinMode(LED, OUTPUT); 
  Serial.begin(9600);
  delay(1500); 
  initProperties();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  temp = random(20,30);
  delay(500);
}

void onLightChange() {
  if(light){
    digitalWrite(LED, HIGH);
  }
  else{
    digitalWrite(LED, LOW);
  }
}

Watch the IoT control on the board 🚀

 

This was a sample of Data Monitoring and Control using Arduino IoT Cloud !! ✨

Follow for more tutorial documentation on Projects and Platforms!

License
All Rights
Reserved
licensBg
0