Internet of things project: Connect Arduino to Ubidots and Android – Part 1

This IoT project explores how to connect Arduino to Ubidots and Android. One important aspect in Arduino Internet of things programmin is how to connect arduino to internet and store date to IoT cloud platforms using arduino ethernet shield. This aspect is important because it is possible to store data in the cloud and then analyze it. Once the data, like sensor values, is on the cloud is possible to access it using smart phones and control remotely the Arduino board.

connect Arduino to Ubidots and Android connect Arduino to Ubidots and Android

This project is build by two different parts:

    1. the first part describes how to collect data from sensors connected to Arduino board and send this information to a cloud platform that stores it.
  • the second part describes how to access to this information using an Android smart phone.

For this purpose, the data is generated by a DHT11 sensor, that reads temperature and humidity. As cloud IoT platform to store data, we will use Ubidots platform. The sensor is connected to Arduino board that uses a Ethernet shield to connect to the network. In this project, the ethernet shield is Wiznet 5500.

Project Overview: connect Arduino to Ubidots and Android

The project overview is shown below:

IoT project that connects Arduino with DHT11 sensor to Android smartphone

As soon as the temperature and humidity sensor starts reading values, it sends them through Arduino board to the cloud platform. The project uses Ubidots to store data in the cloud. This platform is easy to use and can be easily integrated with Arduino. Moreover, it has a built-in dashboard features, so that it is possible to creates interesting dashboard to show, using charts, the values sent from the board.

Building IoT project

The first step is setup the Arduino sketch and the wire connections. The DHT11 sensor is very easy to use and can be integrated easily and fast with Arduino, moreover there is a library that helps developing the system. The picture below shows the schematic of this project:

Arduino sketch with DHT11

In this sketch,  DHT11 sensor is connected to Arduino board, that, in turn, uses the Arduino Ethernet shield to connect to the network to send data. As first step, we check if everything is connected correctly trying to read the value of the temperature and the humidity. The snippet below shows the Arduino sketch to test the sensor:

#include "DHT.h"
#include <spi.h>
#define DHTPIN 2
#define DHTTYPE DHT11


void setup() {

void loop() {

  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  Serial.print("Humidity: ");
  Serial.print(" %t");
  Serial.print("Temperature: ");
  Serial.println(" *C ");

One thing to remember is importing DHT11 library in your Arduino IDE. Running the example you should get the temperature and the humidity.
If everything works correctly, it is time to make things a little more complex adding Ubidots support.
The purpose of this Arduino Internet of things project is sending data to the cloud and store it, so we have to implement the agent that takes care to send the data.
Ubidots provides an example that can be useful. In Arduino, we have to develop an ArduinoHTTP client that calls a JSON service passing the data we want to store in the cloud.
Refering to the Ubidots documentation, it is necessary to create an authentication token that the client has to send. Please read below to know more how to create the token.
In this IoT project, the Arduino HTTP client sends two variable at the same time: temperature and humidity, so the URL to call is:

while the data in JSON format to send is:

 {"variable": "varId", "value":val, "timestamp":timestamp},
 {"variable": "vardId1", "value":val1, "timestamp":timestamp1}

Here the Arduino sketch for HTTP client:

Notice at line 65 and 66 we build the JSON data to pass to the service using the variable ids (please refer below to know how to get the id) and at line 83 we send in the header the authentication token.
The Arduino HTTP client for Ubidots is almost read, it is time to configure the project in Ubidots.

Now, it is necessary to configure the project on Ubidots so that the Arduino client can send data. This can be done using Ubidots web interface.

It is necessary to create two variables:

  1. one that holds temperature values
  2. one that holds humidity values.

Before we have to create a Ubidots project:

Internet of things Ubidots define datasource

Once the project is configured, we can define our variables:

IoT with Arduino using ubidots, define variable

We do the same steps for humidity variable and then we have our dashboard:

Building IoT project using Arduino and ubidots dashboard

As you can see, these two variable have two ids that we used previously when we created the JSON request.

You may like also How to monitor environment parameters: step by step tutorial

The IDs of these variables are used in the Arduino sketch:

// Ubidots Data
String tempVarId = "5656116076254219f78cad12";
String humVarId = "565611777625421b5e91a1ef";

The last step is creating the token:

Ubidots create token with Arduino

Once the variables are configured we can use them to send data.
Running the sketch, Arduino starts sending data to Ubidots. One feature provided by Ubidots is the capability to create a dashboard in an easy way.
For example, for the temperature we can create a simple dashboard to show data sent by Arduino and DHT11:


Ubidots connected to Arduino temperature chart


Ubidots connected to Arduino humidity chart

Below the real Arduino board connected to DHT11 with Ethernet shield.

Arduino and DHT11 connection

In this first part of the Internet of things project, you learned how to connect Arduino to the cloud using Ubidots and Ethernet shield. Arduino read DHT11 data values and sends them to Ubidots.
In the next post, you will know how to read these values from Android Smartphone and how to create charts on smartphones.

More posts...
  • Paulo Penicheiro


    i get this error on lines 62 and 63 ( ubidots_part_I.ino:61:26: error: expected ‘,’ or ‘;’ before ‘variable’
    ubidots_part_I.ino:62:20: error: expected ‘;’ before ‘variable’)

    can u give me some help

    Best regards

    • I modified the source code, \ was missing. Can you give a try and confirm to me if it is working? Thank you


    Thank you for your detailed description!
    But when i tried doing, my data doesn’t reach the ubidots. Why is this? The arduino code has no errors and one doubt of mine is that you have mentioned about creating a project in ubidots. Bt I coudn’t see any such options and instead i created a Device nd then added the variables to it and created dashboard also.Are both the same?
    Also, for testing I passed values to float t and float h ,(the variables.) I commented all the DHT portions and its library. The code as such is working but the data is not being transmitted. Can You help me out?
    Thanks in advance !

    • Yes the steps are correct. You can check on Ubidtos side if the data is present. Try to check if you can invoke the url or there are some hidden errors that you do not show.

  • Nikil

    Thank you for the code! but it initially gave a error on like 62 saying stray , that was solved by putting an extra before the double quotes before tempvar

    OLD(String varString = “[{“variable”: “” + tempVarId + “”, “value”:” + String(tempValue) + “}”;)

    NEW (String varString = “[{“variable”: “” + tempVarId + “”, “value”:” + String(tempValue) + “}”;)

    but the information is not being passed onto ubidots

    Serial output
    Humidity: 19.00 %tTemperature: 24.00 *C
    Sending data…
    POST /api/v1.6/collections/values HTTP/1.1
    Content-Type: application/json
    Content-Length: 112
    X-Auth-Token: i3IZZwXwowXznxvTlCkRp1od8scoTa
    Host: things.ubidots.comn
    [{“variable”: 58cd130b76254225983ebe5f”, “value”:24.00},{“variable”: “58cd1318762542259a53d020”, “value”:19.00}]nConnection [0]

    Humidity: 19.00 %tTemperature: 24.00 *C
    Sending data…
    POST /api/v1.6/collections/values HTTP/1.1
    Content-Type: application/json
    Content-Length: 112
    X-Auth-Token: i3IZZwXwowXznxvTlCkRp1od8scoTa
    Host: things.ubidots.comn
    [{“variable”: 58cd130b76254225983ebe5f”, “value”:24.00},{“variable”: “58cd1318762542259a53d020”, “value”:19.00}]nConnection [0]

    i used the sketch from ubidotsethernet shield an dthe data passes on to ubidots so i kn ow my network and configuration are allright

    Thank You