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

This project is build by two different parts:

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:

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:

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:

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:

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:

one that holds temperature values

one that holds humidity values.

Before we have to create a Ubidots project:

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

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

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

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 dashboard in an easy way.
For example, for the temperature we can create a simple dashboard to show data sent by Arduino and DHT11:

About The Author

I'm an electronic engineer with over 15 years of
experience in computer programming. I'm the author of the book "Android things projects". I'm a MVB at DZone and DZone Guide Author. I have contributed to the IoT guide. I'm the technical reviewer of the book Internet of Things with Arduino Blueprints(published by PacktPub). I love creating IoT projects using Arduino, Raspberry Pi,
Android, and other platforms. I am interested in the convergence
between IoT and the mobile applications. I'm SCEA, SCWCD, and SCJP
certified.
Follow on: Twitter | Linkedin

Paulo Penicheiro

Hi

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’)

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

YADU KRISHNAN K

Hi,
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 !

Sign up for our Newsletter

Enter your email and stay on top of things,

Get SwA updates delivered to your inbox. Article, tips, source code

×

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.