element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Arduino MKR 1010 + Env Shield and the Arduino IoT Cloud
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 27 Jun 2020 1:21 AM Date Created
  • Views 2302 views
  • Likes 3 likes
  • Comments 0 comments
  • mkr 1010
  • arduino iot cloud
  • arduino mkr 1010
  • oled display
  • mkr env sensor shield
  • iot
Related
Recommended

Arduino MKR 1010 + Env Shield and the Arduino IoT Cloud

carmelito
carmelito
27 Jun 2020

This is a continuation of the blog post I posted earlier this week Arduino MKR WiFi 1010 + MKR ENV Shield , as part of this blog post I using am using Arduino MKR 1010 (a MRK family of boards that has WiFi and Bluetooth), MKR Environment Shield to post sensor values to Arduino IoT cloud, and an I2C OLED to display sensor values and to show data posted on the Arduino IoT cloud.   I have always wanted to try Arduino IoT cloud and finally thought that I should give it a try image, given that I received the MKR Environment shield to Roadtest the Arduino MKR 1300 LoRa boards. 

 

The setup was pretty simple, and this was my first time using Arduino Web Editor. I was surprised with all the feature's (here is link that details on the setup - https://www.arduino.cc/en/IoT-Prime/Experiment04 ). The only thing to note, is the 'feature usage' tab on the right, which shows you the amount of storage you have used for Sketches and other files, the number of sketches you have in the cloud, and also the number of compilations. I was using the editor to upload sketches and finally came across and error that said "you have exceeded the number of compilations" image, then I figured out I had to upgrade to the Maker plan which had unlimited compilation time - which you can find more about at - https://store.arduino.cc/digital/create . In addition, I also found a tweet that said get a free upgrade now to Arduino create and followed the link that gave me Maker plan free for 3 months, here is the link https://blog.arduino.cc/2020/03/20/work-remotely-with-arduino-create-get-a-free-upgrade-now/, per the blog post it say you have till June 30th to use the voucher code , image so hurry !!

 

 

Here is picture of the Arduino Cloud IoT dashboard that was setup with the sensor values from the ENV shield.

image

Now since I upgraded to the Maker account this meant i had access to more Properties - which are all boxes that you see above, which include senor values and other boxes like a switch that you can use to trigger something like a relay/Led connected to Arduino MKR 1010, the free account has 5 per thing, and the maker has 20 per thing.

 

In my scenario, I have an OLED display show sensor values from the MKR Environment shield, when the send message button in the cloud dashboard above turned OFF, here is a picture of the OLED , showing Temperature( C), humidity, Illuminance and UVIndex.

image

 

And to send a message to the Arduino MKR 1010 from the Arduino IoT cloud, I type the message in the message box and then turned ON the send message button cloud dashboard, this is basically setup in the Arduino sketch.

image

 

Here is the Arduino sketch that was put together in the Web editor, some of it was auto generate based on the properties setup in the IoT cloud, screenshot below the sketch

//Include the libs for simple I2C 128x32 oled.
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
// 0X3C+SA0 - 0x3C or 0x3D
#define I2C_ADDRESS 0x3C
// Define proper RST_PIN if required.
#define RST_PIN -1
SSD1306AsciiWire oled;
/* 
  Sketch generated by the Arduino IoT Cloud Thing "MKR1010Home"
  https://create.arduino.cc/cloud/things/108fc99f-6b52-4751-97f3-43653107b351 

  Arduino IoT Cloud Properties description

  The following variables are automatically generated and updated when changes are made to the Thing properties

  String mesg;
  float humd;
  float illum;
  float temp;
  float uvind;
  bool led;

  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 <Arduino_MKRENV.h>
#include "thingProperties.h"






String vals ="";

void setup() {
  //pinMode(LED_BUILTIN, OUTPUT);
  // 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
 */
   Wire.begin();
  Wire.setClock(400000L);
#if RST_PIN >= 0
  oled.begin(&Adafruit128x32, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
  oled.begin(&Adafruit128x32, I2C_ADDRESS);
#endif // RST_PIN >= 0
  oled.setFont(Adafruit5x7);
  uint32_t m = micros();
  oled.clear();
}


void loop() {
  ArduinoCloud.update();
  // Your code here 
      if (!ENV.begin()) {
      Serial.println("Failed to initialize MKR ENV shield!");
      while (1);
    }

    temp = ENV.readTemperature();
    illum = ENV.readIlluminance();
    humd = ENV.readHumidity();
    uvind = ENV.readUVIndex();
     
    oled.clear();
    // print sensor values to Serial Monitor
    Serial.print("Temperature = ");
    Serial.print(temp);
    Serial.println(" C");


    Serial.print("Humidity = ");
    Serial.print(humd);
    Serial.println(" %");


    Serial.print("Illuminance    = ");
    Serial.print(illum);
    Serial.println(" lx");
    
    Serial.print("UVIndex    = ");
    Serial.print(uvind);
    Serial.println(" ");
    
    Serial.print("Send Message    = ");
    Serial.print(led);
    Serial.println(" ");
    
    Serial.print("Message from Cloud    = ");
    Serial.print(mesg);
    Serial.println(" ");
    
  vals = "T: "+String(temp)+ "\nH:"+String(humd)+"\nI:" + String(illum)+ "\nUV:"+String(uvind);
  if(led){
   oled.println(mesg);
  }else{
    oled.println(vals);
  }
  delay(20);
}

void onLedChange() {
}

void onMesgChange() {
}

 

image

In addition, once you hit the Edit sketch button a thingProperties.h file was auto-generated, here are the details,  and in the secret tab, you have to update your WiFi SSID and Password.

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


const char THING_ID[] = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx";


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


void onMesgChange();
void onLedChange();
String mesg;
float humd;
float illum;
float temp;
float uvind;
bool led;


void initProperties(){


  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(mesg, READWRITE, ON_CHANGE, onMesgChange);
  ArduinoCloud.addProperty(humd, READ, 30 * SECONDS, NULL);
  ArduinoCloud.addProperty(illum, READ, 30 * SECONDS, NULL);
  ArduinoCloud.addProperty(temp, READ, 30 * SECONDS, NULL);
  ArduinoCloud.addProperty(uvind, READ, 30 * SECONDS, NULL);
  ArduinoCloud.addProperty(led, READWRITE, ON_CHANGE, onLedChange);


}


WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

 

Here is a screenshot of the fancy Web Editor -Serial Monitor in action, receiving a message from the Arduino IoT cloud.

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube