Project tutorial
Control Your IoT Cloud Kit via Arduino Cloud

Control Your IoT Cloud Kit via Arduino Cloud © CC BY

You can use the secure cloud service from Arduino in order to control your device from Internet

  • 576 views
  • 0 comments
  • 2 respects

Components and supplies

Apps and online services

About this project

This is a basic dive with a very new Arduino Cloud service, used for secure and easy to use tools for web connected devices.

We'll be using the Arduino Environmental Shield and The Relay Proto Carrier, creating a Thing that will expose Humidity, Light, Temperature and the two Relays.

First thing, we have to configure an Arduino board to enable it to communicate with the cloud. We'll choose an MKR WiFi 1010. Now that our board is configured, let’s go to Arduino IoT Cloud and the Getting Started guided process will help us configure our board, give it a name and install the keys which will allow it to securely connect to our Cloud using an encrypted channel.

Once we correctly configured our board, we are able to go back to the Cloud and create a new Thing.

We are going to configure the different variables and properties we want the sketch to send to the Cloud. Variables can be Read & Write or Read Only. Names are being reflected in our code, hence we are going to create Humidity, Illuminance, Realy 1 & 2, amd Temperature. While the Names are going to be in capital letters, we'd rather prefer to have the Variable Name with lower ones (humidity, temperature, relay1 etc..)

You can define the type of the variable by selecting it from the drop down menu (ON/OFF Boolean for Relays, with Read & Write Permissions and update When the Value Changes, Read Only and Regular Updates for Temperature, Illuminance or Humidity). You can set convenient minimum and maximum values.

Once you are done, you can press Edit Sketch. You'll be redirected tot he Arduino Online Editor.

In the Editor, we'll have to add few things in order for Arduino to be aware the MKR Environmental shield is on top of the board and the two relays are sitting on pin 1 and 2.

Look and Import Arduino_MKRENV.h and declare the two relays

#include <Arduino_MKRENV.h>
#include "thingProperties.h"
#define POLL_RATE 10*1000
int RELAY1 = 1;
int RELAY2 = 2;
unsigned long elaps = 0;

We also have to make the shield start in setup(), as well as setting the two relays as outputs.

 // Initialize ENV Shield
 ENV.begin();
 pinMode(RELAY1,OUTPUT);
 pinMode(RELAY2,OUTPUT);

in the loop, we update the thw data on every ArduinoCloud.update();

void loop() {
 ArduinoCloud.update();
 if(millis()-elaps > POLL_RATE){
   temperature = ENV.readTemperature();
   humidity    = ENV.readHumidity();
   illuminance = ENV.readIlluminance();
 }

Code

ENV Monitor

Comments

Add projectSign up / Login