Home > Projects > IoT Cloud – Getting Started

IoT Cloud – Getting Started

Summary of IoT Cloud – Getting Started


This tutorial walks through connecting an Arduino MKR board (MKR1000 or MKR WiFi 1010) to Arduino IoT Cloud, creating a Thing, adding Properties, and controlling hardware (LED, potentiometer, pushbutton) from the Cloud. It explains wiring, generated sketch files (thingProperties.h and .ino), configuring WiFi secrets, uploading code, and using callbacks to sync property changes. It also covers mapping analog readings, debouncing a button with FTDebouncer, and viewing/debugging via the Cloud Dashboard and Serial Monitor.

Parts used in the Arduino IoT Cloud Tutorial:

  • Arduino MKR1000 (or MKR WiFi 1010)
  • Arduino MKR IoT Bundle (optional)
  • Breadboard (generic)
  • LED (generic, 20mA)
  • Resistor 221 ohm (example used 150Ω)
  • Rotary potentiometer (generic)
  • SparkFun Pushbutton switch 12mm
  • Resistor 10k ohm (pull-down)
  • Arduino Web Editor (software)
  • Arduino IoT Cloud (online service)

Get familiar with the Arduino IoT Cloud and take your first steps into the world of connected objects.

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
A MKR1010 is also a perfect option, or you could use a MKR IOT Bundle (see below)
× 1
Arduino MKR IoT Bundle
Arduino MKR IoT Bundle
× 1
Breadboard (generic)
Breadboard (generic)
× 1
LED (generic)
LED (generic)
A generic 20mA LED
× 1
Resistor 221 ohm
Resistor 221 ohm
In our example we used a 150Ω resistor to limit the current flowing through the LED which will be powered by 3.3 Volts HIGH signal from the pin
× 1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
× 1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
× 1
Resistor 10k ohm
Resistor 10k ohm
This will act as a Pull-Down resistor on the button pin
× 1

Software apps and online services

Arduino Web Editor
Arduino Web Editor
Arduino IoT Cloud

Story

From the editor, GO TO IOT CLOUD and create a new property named toggle, with Type ON/OFF (Boolean), Permission Read only and Update When the value changes.

Once again EDIT CODE and we’ll be back to the editor. A quick glance at thingProperties.h will show that a new variable Toggle has been defined and associated to its property via ArduinoCloud.addProperty(...).

In our .ino file we’ll define the new pin and two variables related to the button state (more on this later)

#define BUTTON_PIN 5
int btnState;
int btnPrevState = 0;

btnPrevState is needed because we want the property to be updated only once when the button is pressed and not when it is released.

Then, in the setup() we set the pinMode for this pin to INPUT

pinMode(BUTTON_PIN, INPUT);

And finally we add these lines towards the end of the loop()

btnState = digitalRead(BUTTON_PIN);
if (btnPrevState == 0 && btnState == 1) {
 toggle = !toggle;
}
btnPrevState = btnState;

In this way the button acts as a toggle and when pressing it we should see the switch on the cloud changing accordingly and flipping between ON and OFF.

Amazing, right? How about uploading the new code and testing out how our circuit interacts with the Dashboard? Let’s do that.

Once again EDIT CODE and we’ll be back to the editor. A quick glance at thingProperties.h will show that a new variable Toggle has been defined and associated to its property via ArduinoCloud.addProperty(...).

In our .ino file we’ll define the new pin and two variables related to the button state (more on this later)

#define BUTTON_PIN 5
int btnState;
int btnPrevState = 0;

btnPrevState is needed because we want the property to be updated only once when the button is pressed and not when it is released.

Then, in the setup() we set the pinMode for this pin to INPUT

pinMode(BUTTON_PIN, INPUT);

And finally we add these lines towards the end of the loop()

btnState = digitalRead(BUTTON_PIN);
if (btnPrevState == 0 && btnState == 1) {
 toggle = !toggle;
}
btnPrevState = btnState;

In this way the button acts as a toggle and when pressing it we should see the switch on the cloud changing accordingly and flipping between ON and OFF.

Amazing, right? How about uploading the new code and testing out how our circuit interacts with the Dashboard? Let’s do that.

Once again EDIT CODE and we’ll be back to the editor. A quick glance at thingProperties.h will show that a new variable Toggle has been defined and associated to its property via ArduinoCloud.addProperty(...).

In our .ino file we’ll define the new pin and two variables related to the button state (more on this later)

#define BUTTON_PIN 5
int btnState;
int btnPrevState = 0;

btnPrevState is needed because we want the property to be updated only once when the button is pressed and not when it is released.

Then, in the setup() we set the pinMode for this pin to INPUT

pinMode(BUTTON_PIN, INPUT);

And finally we add these lines towards the end of the loop()

btnState = digitalRead(BUTTON_PIN);
if (btnPrevState == 0 && btnState == 1) {
 toggle = !toggle;
}
btnPrevState = btnState;

In this way the button acts as a toggle and when pressing it we should see the switch on the cloud changing accordingly and flipping between ON and OFF.

Amazing, right? How about uploading the new code and testing out how our circuit interacts with the Dashboard? Let’s do that.

Schematics

Schematic

Schematic for the circuit

Code

/*
Sketch generated by the Arduino IoT Cloud Thing “testThing”
https://create.arduino.cc/cloud/things/d276ab77-67cb-420b-9ea4-bd34cdf385d9

Arduino IoT Cloud Properties description

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

bool switchState;
int potentiometerValue;
bool ledState;

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 <FTDebouncer.h>

#define LED_PIN 2
#define POT_PIN A1
#define BUTTON_PIN 5

FTDebouncer buttons;

void setup() {
pinMode(LED_PIN, OUTPUT);
buttons.addPin(BUTTON_PIN, LOW);
buttons.init();

/*
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 3
*/
setDebugMessageLevel(2);

// 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);
}

void loop() {
buttons.update();
ArduinoCloud.update();
// Your code here
int angleSensor = analogRead(A1);
angle = map(angleSensor, 0, 1023, 0, 270);
}

void onLightChange() {
digitalWrite(LED_PIN, light);
Serial.print(“The light is “);
if (light) {
Serial.println(“ON”);
} else {
Serial.println(“OFF”);
}
}

void onPinActivated(uint8_t pinNr) {
// do something according to the _pinNR that is triggered. For instance:
Serial.println(pinNr);
toggle = !toggle;
}

void onPinDeactivated(uint8_t pinNr) {
// do something according to the _pinNR that is triggered. For instance:
Serial.println(pinNr);
}

This library makes it easier to implement push and release actions for physical buttons, without the burden to track time, buttons states and change of state between LOW and HIGH. Create a Debounce Manager, add a pin to keep track of and let the library call two functions for when the button is pressed or released. More info on the GitHub repository, as well as in the video.

Debounce Library for Arduino — Read More

Source : IoT Cloud – Getting Started

Quick Solutions to Questions related to Arduino IoT Cloud Tutorial:

  • What board can I use for this Arduino IoT Cloud tutorial?
    You can use an Arduino MKR1000 or a MKR WiFi 1010; an MKR IoT Bundle is also an option.
  • How is the LED wired to the MKR board?
    The positive leg of the LED connects to Digital Pin 2 and the negative leg to ground through a 150 Ohm resistor; power the breadboard from Vcc.
  • How do I make the board connect securely to Arduino IoT Cloud?
    Use the Getting Started wizard to configure the board, install keys, and provide WiFi credentials in the Secret tab (SECRET_SSID and SECRET_PASS).
  • How do I create a cloud-controllable LED property?
    Create a Property named light of type ON/OFF (Boolean) with Read and Write permission and Update When the value changes.
  • How is the potentiometer value mapped to a cloud property?
    Connect the potentiometer signal to Analog Pin A1, read with analogRead, and map the 0-1023 value to 0-270 and assign it to the int angle property.
  • How is the push button implemented to toggle a cloud property?
    Wire the button between Vcc and Digital Pin 5 with a 10k pull-down to ground, read the pin, detect rising edge, and flip the toggle boolean property.
  • What files does Arduino IoT Cloud generate for the Thing?
    It generates ReadMe.adoc, thingProperties.h, the main .ino sketch, and a Secret tab for WiFi credentials.
  • How do callbacks work when a property changes from the Dashboard?
    A callback function like onLightChange is declared and called whenever the corresponding property value changes from Arduino IoT Cloud.
  • How can I avoid button bounce issues?
    Use the FTDebouncer library to manage debounced press and release actions and register the button pin with the debouncer.
  • How can I view connection and debug information?
    Enable Serial output and set setDebugMessageLevel to a higher level (e.g., 2 or 3) to see WiFi and Cloud connection logs in the Serial Monitor.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top