Trybotics Logo

Your Environmental Data on Arduino IoT Cloud © CC BY-NC

DESCRIPTION

With this project, you will see the environmental data acquired by the ENV Shield on a web page of the Arduino Cloud. The data is collected and sent to the Arduino Cloud by the MKR GSM 1400 board that acts as a host for the shield and performs all the communications tasks.

By making this project you will learn how to read the data from the various sensors available on the ENV Shield, and you also learn how to visualise data on the widgets available in the Arduino Cloud.

What you need

The project uses an Arduino MKR GSM 1400, the antenna, a battery pack, one data SIM card, the MKR ENV Shield, and a free account on Arduino IoT Cloud:

  • The main component is the Arduino MKR GSM 1400. This board manages calculations and communications thanks to its SAMD21 core and the SARA GSM module;
  • Antenna and battery pack are connected to the MKR GSM 1400 and are respectively used to allow a better connection to the GSM network and to power the device when an alternative power supply is not available;
  • The microSIM card is required to allow the connection to the GSM network and te internet;
  • The MKR ENV Shield is the Arduino shield that provides environmental sensors to measure temperature, humidity, pressure, light and UV.
  • PIN, APN and access credentials are needed to connect to the Data network.

The hardware configuration is relatively simple: it requires only the MKRGSM 1400, the Antenna, the MKR ENV shield and the battery pack

Put the MKR ENV Shield on top of the MKR GSM 1400 and check that the two are aligned with matching labels on their connectors

The antenna, the SIM and the battery pack should be connected in their own connectors and slot on top and bottom of the MKR GSM 1400:

Software structure

The software we wrote for this project relies on the code auto generated by Arduino IoT cloud APIs to show the data received from the MKR GSM board as well as on the MKRENV library that allows us to read the values measured by the sensor :

  • Arduino cloud: will be configured to show six properties (variables), these show the various measures received from the MKR GSM 1400.
  • The Arduino sketch is auto generated and it includes the ArduinoIoTCloud library and the MKRENV library. The first manages the connectivity of the SARA GSM module while the second is the one where all the APIs to read the sensors are.

Sketch

The first code section is used to includes the libraries required by the application.

The thingProperties.h include all the GSM connection functionalities and cloud connection management; the only information required from the user are the credentials necessary to establish a connection with the GSM network (PIN, APN, user and password).

Arduino IoT Cloud authenticates the connected device using a key that is stored inside the board's cryptochip and therefore the security of the connection is granted.

The MKRENV library includes all the functionalities to read the values measured by the sensors on the shield.

#include "thingProperties.h" #include <MKRENV.h> 

After the include section we define all the variable used to store the values read from the sensors:

int humtmp; int luxtmp; int prestmp; int temptmp; int uvatmp; int uvbtmp; int uvitmp; 

The setup section allows to initialise all the object used by the sketch, by the Arduino IoT cloud and it also initialises the properties. Setup plays a central role because ArduinoCloud.begin(); establish the connection and initialises all structures to allow the transmission of the properties value to the cloud:

void setup() {  // Initialize serial and wait for port to open:  Serial.begin(9600);  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found  delay(1500);  // Defined in thingProperties.h  initProperties();  // Connect to Arduino IoT Cloud  ArduinoCloud.begin(ArduinoIoTPreferredConnection);  /* The following function allows you to obtain more information related to the state of network and IoT Cloud connection and errors the higher number the more granular information you’ll get. The default is 0 (only errors). Maximum is 4 */  setDebugMessageLevel(4);  ArduinoCloud.printDebugInfo(); if (!ENV.begin()) { Serial.println("Failed to initialize MKR ENV shield!"); while(1);  } } 

Last code section is the loop where the sketch queries the sensors of the MKR ENV Shield. After each reading the sketch updates the properties variables and through the ArduinoCloud.update(); it updates the matching value on the cloud:

void loop() {  ArduinoCloud.update();  // Your code here  humtmp = int(ENV.readHumidity());  luxtmp = int(ENV.readLux());  prestmp = int(ENV.readPressure());  temptmp = int(ENV.readTemperature());  uvatmp = int(ENV.readUVA());  uvbtmp = int(ENV.readUVB());  uvitmp = int(ENV.readUVIndex());  pressure = prestmp;  temperature = temptmp;  humidity = humtmp;  uvi = uvitmp;  uva = uvatmp;  uvb = uvbtmp;  lux = luxtmp;  delay(100); } 

How to set up and use

Connect all the parts together, paying attention to the antenna connector that is quite delicate, then connect your MKR GSM 1400 to the computer and log onto your Arduino Cloud account.

You need to follow the procedure explained in the Arduino Cloud Getting Started and create the properties as specified in the following table, remembering that each name is case sensitive:

Each time you add a new widget you are required to fill a form like the one below.

If you filled properly each property form, you should end up with a situation as the one depicted below.

When all the properties are made, click on the button edit code. You will be redirected to the Arduino editor where you have to copy in the first tab of the project the following sketch:

/*  Sketch generated by the Arduino IoT Cloud Thing "env_shield"  https://create.arduino.cc/cloud/things/829941ed-efdd-4572-91c0-e93a732192ec  Arduino IoT Cloud Properties description  The following variables are automatically generated and updated when changes are made to the Thing properties  int humidity;  int lux;  int pressure;  int temperature;  int uva;  int uvb;  int uvi;  Properties which are marked as READ/WRITE in the Cloud Thing will also have functions  which are called when their values are changed from the Dashboard.  These functions are generated with the Thing and added at the end of this sketch. */ #include "thingProperties.h" #include <MKRENV.h> int humtmp; int luxtmp; int prestmp; int temptmp; int uvatmp; int uvbtmp; int uvitmp; void setup() {  // Initialize serial and wait for port to open:  Serial.begin(9600);  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found  delay(1500);  // Defined in thingProperties.h  initProperties();  // Connect to Arduino IoT Cloud  ArduinoCloud.begin(ArduinoIoTPreferredConnection);  /*  The following function allows you to obtain more information  related to the state of network and IoT Cloud connection and errors  the higher number the more granular information you’ll get.  The default is 0 (only errors).  Maximum is 4 */  setDebugMessageLevel(4);  ArduinoCloud.printDebugInfo(); if (!ENV.begin()) {  Serial.println("Failed to initialize MKR ENV shield!");  while(1);  } } void loop() {  ArduinoCloud.update();   humtmp = int(ENV.readHumidity());  luxtmp = int(ENV.readLux());  prestmp = int(ENV.readPressure());  temptmp = int(ENV.readTemperature());  uvatmp = int(ENV.readUVA());  uvbtmp = int(ENV.readUVB());  uvitmp = int(ENV.readUVIndex());  pressure = prestmp;  temperature = temptmp;  humidity = humtmp;  uvi = uvitmp;  uva = uvatmp;  uvb = uvbtmp;  lux = luxtmp;  delay(100); } void onHumidityChange() {  // Do something } void onLuxChange() {  // Do something } void onPressureChange() {  // Do something } void onTemperatureChange() {  // Do something } void onUvaChange() {  // Do something } void onUvbChange() {  // Do something } void onUviChange() {  // Do something } void onTestValAggiuntoChange() {  // Do something } void onAChange() {  // Do something } void onBChange() {  // Do something } 

Upload the sketch on the board, and when the connection is established the MKR GSM starts to send the measures received by the MKR ENV Shield and these are shown on the dashboard of the Thing's page, in the properties manager:

The sketch on Arduino Create is available below.

Description:

Description:

With this project, you will see the environmental data acquired by the ENV Shield on a web page of the Arduino Cloud. The data is collected and sent to the Arduino Cloud by the MKR GSM 1400 board that acts as a host for the shield and performs all the communications tasks.

By making this project you will learn how to read the data from the various sensors available on the ENV Shield, and you also learn how to visualise data on the widgets available in the Arduino Cloud.

What you need

The project uses an Arduino MKR GSM 1400, the antenna, a battery pack, one data SIM card, the MKR ENV Shield, and a free account on Arduino IoT Cloud:

  • The main component is the Arduino MKR GSM 1400. This board manages calculations and communications thanks to its SAMD21 core and the SARA GSM module;
  • Antenna and battery pack are connected to the MKR GSM 1400 and are respectively used to allow a better connection to the GSM network and to power the device when an alternative power supply is not available;
  • The microSIM card is required to allow the connection to the GSM network and te internet;
  • The MKR ENV Shield is the Arduino shield that provides environmental sensors to measure temperature, humidity, pressure, light and UV.
  • PIN, APN and access credentials are needed to connect to the Data network.

The hardware configuration is relatively simple: it requires only the MKRGSM 1400, the Antenna, the MKR ENV shield and the battery pack

Put the MKR ENV Shield on top of the MKR GSM 1400 and check that the two are aligned with matching labels on their connectors

The antenna, the SIM and the battery pack should be connected in their own connectors and slot on top and bottom of the MKR GSM 1400:

Software structure

The software we wrote for this project relies on the code auto generated by Arduino IoT cloud APIs to show the data received from the MKR GSM board as well as on the MKRENV library that allows us to read the values measured by the sensor :

  • Arduino cloud: will be configured to show six properties (variables), these show the various measures received from the MKR GSM 1400.
  • The Arduino sketch is auto generated and it includes the ArduinoIoTCloud library and the MKRENV library. The first manages the connectivity of the SARA GSM module while the second is the one where all the APIs to read the sensors are.

Sketch

The first code section is used to includes the libraries required by the application.

The thingProperties.h include all the GSM connection functionalities and cloud connection management; the only information required from the user are the credentials necessary to establish a connection with the GSM network (PIN, APN, user and password).

Arduino IoT Cloud authenticates the connected device using a key that is stored inside the board's cryptochip and therefore the security of the connection is granted.

The MKRENV library includes all the functionalities to read the values measured by the sensors on the shield.

#include "thingProperties.h"
#include <MKRENV.h>

After the include section we define all the variable used to store the values read from the sensors:

int humtmp;
int luxtmp;
int prestmp;
int temptmp;
int uvatmp;
int uvbtmp;
int uvitmp;

The setup section allows to initialise all the object used by the sketch, by the Arduino IoT cloud and it also initialises the properties. Setup plays a central role because ArduinoCloud.begin(); establish the connection and initialises all structures to allow the transmission of the properties value to the cloud:

void setup() {
 // Initialize serial and wait for port to open:
 Serial.begin(9600);
 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
 delay(1500);
 // Defined in thingProperties.h
 initProperties();
 // Connect to Arduino IoT Cloud
 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
 /*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
 setDebugMessageLevel(4);
 ArduinoCloud.printDebugInfo();
if (!ENV.begin()) {
Serial.println("Failed to initialize MKR ENV shield!");
while(1);
 }
}

Last code section is the loop where the sketch queries the sensors of the MKR ENV Shield. After each reading the sketch updates the properties variables and through the ArduinoCloud.update(); it updates the matching value on the cloud:

void loop() {
 ArduinoCloud.update();
 // Your code here
 humtmp = int(ENV.readHumidity());
 luxtmp = int(ENV.readLux());
 prestmp = int(ENV.readPressure());
 temptmp = int(ENV.readTemperature());
 uvatmp = int(ENV.readUVA());
 uvbtmp = int(ENV.readUVB());
 uvitmp = int(ENV.readUVIndex());
 pressure = prestmp;
 temperature = temptmp;
 humidity = humtmp;
 uvi = uvitmp;
 uva = uvatmp;
 uvb = uvbtmp;
 lux = luxtmp;
 delay(100);
}

How to set up and use

Connect all the parts together, paying attention to the antenna connector that is quite delicate, then connect your MKR GSM 1400 to the computer and log onto your Arduino Cloud account.

You need to follow the procedure explained in the Arduino Cloud Getting Started and create the properties as specified in the following table, remembering that each name is case sensitive:

Each time you add a new widget you are required to fill a form like the one below.

If you filled properly each property form, you should end up with a situation as the one depicted below.

When all the properties are made, click on the button edit code. You will be redirected to the Arduino editor where you have to copy in the first tab of the project the following sketch:

/* 
 Sketch generated by the Arduino IoT Cloud Thing "env_shield"
 https://create.arduino.cc/cloud/things/829941ed-efdd-4572-91c0-e93a732192ec 
 Arduino IoT Cloud Properties description
 The following variables are automatically generated and updated when changes are made to the Thing properties
 int humidity;
 int lux;
 int pressure;
 int temperature;
 int uva;
 int uvb;
 int uvi;
 Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
 which are called when their values are changed from the Dashboard.
 These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <MKRENV.h>
int humtmp;
int luxtmp;
int prestmp;
int temptmp;
int uvatmp;
int uvbtmp;
int uvitmp;
void setup() {
 // Initialize serial and wait for port to open:
 Serial.begin(9600);
 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
 delay(1500); 
 // Defined in thingProperties.h
 initProperties();
 // Connect to Arduino IoT Cloud
 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
 /*
    The following function allows you to obtain more information
    related to the state of network and IoT Cloud connection and errors
    the higher number the more granular information you’ll get.
    The default is 0 (only errors).
    Maximum is 4
*/
 setDebugMessageLevel(4);
 ArduinoCloud.printDebugInfo();
if (!ENV.begin()) {
   Serial.println("Failed to initialize MKR ENV shield!");
   while(1);
 }
}
void loop() {
 ArduinoCloud.update();
  
 humtmp = int(ENV.readHumidity());
 luxtmp = int(ENV.readLux());
 prestmp = int(ENV.readPressure());
 temptmp = int(ENV.readTemperature());
 uvatmp = int(ENV.readUVA());
 uvbtmp = int(ENV.readUVB());
 uvitmp = int(ENV.readUVIndex());
 pressure = prestmp;
 temperature = temptmp;
 humidity = humtmp;
 uvi = uvitmp;
 uva = uvatmp;
 uvb = uvbtmp;
 lux = luxtmp;
 delay(100);
}
void onHumidityChange() {
 // Do something
}
void onLuxChange() {
 // Do something
}
void onPressureChange() {
 // Do something
}
void onTemperatureChange() {
 // Do something
}
void onUvaChange() {
 // Do something
}
void onUvbChange() {
 // Do something
}
void onUviChange() {
 // Do something
}
void onTestValAggiuntoChange() {
 // Do something
}
void onAChange() {
 // Do something
}
void onBChange() {
 // Do something
}

Upload the sketch on the board, and when the connection is established the MKR GSM starts to send the measures received by the MKR ENV Shield and these are shown on the dashboard of the Thing's page, in the properties manager:

The sketch on Arduino Create is available below.

Description:

Your Environmental data on Arduino IoT Cloud

Description:


YOU MIGHT ALSO LIKE