Hey guys, this project tells you all about the Ubidots IoT platform and how to get the most out of it. For this, I will connect my particle photon to the Ubidots platform via Web hook functionality.
This is a Temperature, Humidity and Air Quality monitoring System powered by the particle photon which monitors all the conditions in real time and this data can be viewed on the Ubidots Dashboard with wonderful visual and graphic images for better understanding and analysis of data.
So, before starting, just go to the Ubidots site and see all the features that it can provide:
Then sign up to create a free account and obtain the one month free trial of the Ubidots industrial platform to create wonderful apps and visualize different data using exceptional graphics provided.
Now, after you have completed this, lets start with our project.
1. The Hardware part of the projectFirst, let's create the hardware required for this project. This is a very easy to make circuit and requires the following components:
1. Particle Photon
2. DHT11 temperature and humidity sensor
3. MQ135Airqualitysensor
4. 2 channel relay module(generic)
5. Jumper Wires
6.Wire to power the particle photon
7.Power bank to power the photon
The purpose of using the power bank is to make the whole system easy to move from 1 place to another. The images of this components are shown below:
Now that we have all the components ready, lets build our project according to the given schematic below.
After you have connected the circuit according the given schematic, it will look something like this:
I have taken a plastic box and created holes for wire and sensor outlets. But if you have access to a 3D printer, feel free to make a far better and rugged box.
Now that we have the system ready, let's move on to the main part, that is integrating the particle cloud with the ubidots platform. The block diagram for it is as follows:
To use Ubidots, first we need to setup the particle build environment for it. For that, you need the following things:
- Any particle device
- Micro USB cable
Setting up your Particle device
If you are not familiar with Particle and their Webhook feature - you can read up on this connection method here.
To begin your Particle - Ubidots connection first, you will need to setup your Particle device (Photon, Core, or Electron) within your particle account. Click here for simple steps to setting up your device with Particle's device platform.
After to claiming your devices to the Particle cloud follow the next steps:
- Go to your particle account and log in.
- Click on Console from the left menu.
- Click on Integrations button and press in + NEW INTEGRATION.
- Choose Webhook and press on label Webhook Builder.
- Next, you will need to create a webhook called “temperature” pointing to Ubidots API. To get a better idea how the Ubidots API works, I recommend you read the REST API Reference.
The easiest way to send values to Ubidots is specifying the Device label in the URL, as you can see on the link below:
https://things.ubidots.com/api/v1.6/devices/{LABEL_DEVICE}/
In this case, we're going to assign the Device ID of the Particle Device to make it unique. For this we're going to use the pre defined webhook variable available to use:
- {{PARTICLE_DEVICE_ID}}: The ID of the device that triggered the web hook. It will be assign to the URL the ID of the device selected automatically.
Also, do not forget assign your Ubidots TOKEN to the end the URL because this is the key to publishing events to your Ubidots account.
URL: https://things.ubidots.com/api/v1.6/devices/{{PARTICLE_DEVICE_ID}}/?token={Ubidots_TOKEN}
If you don't know how locate your Ubidots TOKEN, please reference this article:
Now that you have the parameters needed to build the URL, fill the text box.
NOTE: Do not forget select the Device, if you don't select it will not create the device in Ubidots.
- Select Advanced Settings > Form.
Body (form option): {“temperature”: {{PARTICLE_EVENT_VALUE}}
On the option "INCLUDE DEFAULT DATA" press No, to erased the JSON data that Particle sends by default:
When you finish entering your unique info - complete with CREATE WEBHOOK.
Before we move on, let's review the Integration Info to verify everything it's okay.
Now with the Webhook configured, it is time to code! :)
First, go back to the Build console, in the bottom-left menu you will find the Build icon, press it.
Next select the Code icon from the menu.Then CREATE NEW APP and assign a name of your preference to your new app.
In this case, we called it "UBIDOTS-WEBHOOK"
Now we're going to provide you with the codes to pass data through the Particle Webhook to Ubidots and visa-versa.
Now as done for the temperature integration, we will do the same process for other variables that we need, that is humidity, ppm value, co2_ppm and the resistance value of the MQ135 sensor. So, after the integrations are done, your integration tab should look something like this:
After this process is done, now we are ready to code for connecting the particle cloud with Ubidots.
CodingPart:
Now, the first step is to create a new app and name is as you want. I have named it Ubidots. Then include all the necessary libraries required for this project:
This is what your particle build app window should look like after all the libraries are included. Now we are ready to code:
// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"
#include "MQ135.h"
// DHT parameters
#define DHTPIN 2
#define DHTTYPE DHT11
int number = 0;
int state = 0;
MQ135 gasSensor = MQ135(0);
float rzero = gasSensor.getRZero();
int ppm = gasSensor.getPPM();
// Variables
int temperature;
int humidity;
// DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
// Start DHT sensor
dht.begin();
}
void loop() {
//starting the Blynk app
//get the temperature and humidity values
temperature = dht.getTempCelcius();
humidity = dht.getHumidity();
String data = String(temperature);
String data1 = String(humidity);
//calculating the air quality parameters
int co2_ppm = gasSensor.getPPM();
int ppm = co2_ppm / 4;
// Publish data on particle console
Particle.publish("temperature",data);
delay(2000);
Particle.publish("humidity",data1);
delay(2000);
Spark.publish("co2_ppm", String(co2_ppm));
delay(2000);
Spark.publish("resistance", String(rzero));
delay(2000);
Spark.publish("ppm",String(ppm));
delay(2000);
}
Make sure that the first argument name in the Spark.publish() function is the same as the name of the integrations that we created as it is the thing which connects this variables to Ubidots. All the other details are given in the form of comments in the code itself.
Now we are all set, so we will save the code, verify it and flash it to our particle device.
After, that open the console and see if the data is getting sent to the ubidots platform without any errors. It should look something like this:
So, if this is the same thing you see on your own console, then we can now move on to the next step, that is setting up the Ubidots dashboard.
3. Setting up the Ubidots platformNow that all the things are complete in the particle part of the project, lets move on to Ubidots platform. As stated above, you should have created the free ubidots account by now. After you have run the code on the particle, the ubidots will directly detect this and your device will be present under the devices tab of the device management option.
After you open that tab, you will see the devices listed and in that, you will have a device whose name is same as your particle id, so its better to rename it to a desired name. I have renamed it as My photon, as shown below:
It will already have all the 5 variables we created in particle integrations tab so we don't need to create any new variables. When we open the device by clicking on it, we see the following window:
You can see that all the variables have the values which are first read from the sensors, then published on the particle console and then sent to Ubidots through webhook functionality.
Now, we can visualize the same readings on the Ubidots dashboard with several graphical images like gauges, tank level indicators, charts, graphs etc.
Now, we will mostly use the metric, indicator and chart options for this project. First, we will add some indicators to view the obtained data:
With the same procedure, add some metrics and charts for analysis of obtained data. After everything is done, your dashboard will look something like this:
So, now you can view and analyze your data with ease using ubidots platform!
4. Ubidots event managementApart from the dashboard feature, you can add various events for your ubidots app which are triggered after certain conditions are met and produce certain results.
To create an event, go to the Device management tab, and click on the Events option:
After you click on the events option, the following window opens:
To create a new event, click on the create event button, after which you will see the following on you screen-
Now, select the variable on which you want to apply a condition, for example a event is triggered if the temperature variable is more than 30 degrees for 1 minute. Then the second step is to select what result is produced if an event is triggered. It will be under the then actions tab:
You can perform the following actions when an event is triggered:
I have shown the email functionality in this project, so select it and then add the email id and the message you want to send, then click the blue arrow to continue:
Now you will be asked when and in what time range will your event would be triggered. Then click on the green arrow and the event will be successfully created.
I have created 2 events for humidity and temperature that send an email to the specified email id after a certain threshold values are crossed. The email alerts will be like this:
So, this is it, the project is finally complete! Enjoy building it. Here is the tutorial video for the project.
Please feel free to contact me if you have any doubts regarding any of my projects.
Comments