How to connect an Arduino

In this tutorial, we will learn how to connect an Arduino with Ethernet shield to send data to the cloud.

Content:

Preparing the Cloud

Before we dive in into the Arduino code and library, let’s first set up your device within Controllino Cloud.

Step 1

In the left-side menu, click on DEVICE. After that, you will see the round “+” icon on the right-bottom of your screen. Click on it to add an entity group.

Now, you probably wonder… “What the heck is an entity group? I want to add devices!” Let’s explain this topic before we continue:

An entity group in that case is basically just a group of devices. Let’s assume you have a building with several rooms, then you could group your devices by room. This forces you to organize your devices from the beginning and will make the management of them way easier in the future.

Step 2

Now that you know what en entity group is, give it a name and a description. After that, you can already save the entity group or share it with other users within your cloud. For now, we will just save it.

Step 3

Open up your device group and klick on the + icon on the top-right. We will add a device to the cloud.

Step 4

A new window will open up. Here, you will be prompted to give your device a name, a description and some other settings. For the sake of simplicity, we will ignore the other options for now and just save the device. For that, click on the Add button in the bottom right corner.

Step 5

A new window will open up. Here, you will be prompted to give your device a name, a description and some other settings. For the sake of simplicity, we will ignore the other options for now and just save the device. For that, click on the Add button in the bottom right corner.

That’s it! You have now successfully created a new device.

Preparing the Arduino IDE

Now that we have prepared the cloud, let’s dive in into the Arduino part. We will  setup Arduino IDE by installing the Controllino Cloud library

Step 1

Download the Controllino Cloud library by clicking on the button below. Alternatively, you can also visit the Downloads page and download it from there.

Step 2

Open up Arduino IDE. Navigate to Sketch > Include Library > Add .ZIP LibrarySelect the option to Add .ZIP Library

You will be prompted to select the library you would like to add. Navigate to the previously downloaded .zip file’s location and choose it.

Step 3

Return to the Sketch > Include Library menu. You should now see the library at the bottom of the drop-down menu. It is ready to be used in your sketch.

Write the Arduino code

Okay, we’re almost done – now the fun part begins! We will write some example code in Arduino IDE that will send three variables to Controllino Cloud: Temperature, Humidity and Version Number.

Step 1

Click on the download button below to download the example Arduino sketch. Open it up in Arduino IDE. Below, we will explain what each part of the code does.

We will not explain the regular loop() and setup() functions and other things that you will find in every Arduino sketch. We assume that you already know how to program for Arduino within Arduino IDE. 

Nevertheless: If you want more information about how to program your Arduino, please visit the official website to learn more.

#include “ControllinoCloud.h”

This code line includes the Controllino Cloud library to the sketch, which will enable the usage of specific functions that will make connecting your Arduino to the cloud a breeze.

int temperature = 21;
int humidity = 80;

String version = “Arduino Example 1.0”;

Here we declare the variables that we want to send to the cloud.

In our case, we are declaring two integer variables temperature and humidity, as well as a string called version where we just send some text to the cloud.

Here we are just sending some fake values to the cloud. If you have a temperature and humidity sensor laying around, you can of course write some additional code to send real values to the cloud.

cc.sendTelemetry(temperature);
cc.sendTelemetry(humidity);

cc.sendAttribute(version);

This code line includes the Controllino Cloud library to the sketch, which will enable the usage of specific functions that will make connecting your Arduino to the cloud a breeze.

Step 2

Click on the download button below to download the example Arduino sketch. Open it up in Arduino IDE. Below, we will explain what each part of the code does.