Sending BMP Sensor Data to Ubidots Using NodeMCU

NodeMCU ESP8266 with Ubidots

Many IoT cloud platforms have emerged in the last few years to cater to the increasing network of IoT devices. These IoT cloud platforms can be used to manage, process, and transfers the information from IoT devices to cloud or from cloud to the connected device with the help of the Internet. Apart from transferring the information, these platforms can also be used for controlling devices like for example, the Home automation system.

 

We have already used some of the popular IoT platforms like ThingSpeak, Adafruit IO, Blynk, Google Firebase, etc. to build many IoT projects.

 

Today we will explore another IoT cloud platform- Ubidots. Here we interface the NodeMCU ESP8266 with Ubidots IoT cloud to send Temperature, Pressure, and Altitude data from the BMP180 sensor. Uploaded data can also be visualized on Ubidots Dashboard with the help of Widgets.

 

Components Required

  • NodeMCU ESP8266
  • BMP180 Sensor
  • Jumper Wires

 

Ubidots NodeMCU Circuit Diagram

Circuit Diagram for Ubidots NodeMCU is very simple and only the BMP180 sensor is connected with NodeMCU.

Ubidots NodeMCU Circuit Diagramm

Connect the VIN and GND pin of BMP180 to 3.3V and GND of NodeMCU. Do not connect the Sensor directly to 5V because it can damage the Sensor permanently. Connect SCL and SDA pins of BMP180 to D1 and D2 pins of NodeMCU, respectively.

 

BMP180 Pressure Sensor

BMP180 is a Digital Barometric Sensor Module compatible with Arduino and primarily used to measure the absolute pressure, temperature using a digital barometer. It has measuring range from 300 to 1100hPa with an accuracy down to 0.02 hPa in advanced resolution mode. It is based on piezo-resistive technology for high efficiency, ruggedness, and long term stability. The BMP180 is a very small module with 1mm x 1.1mm (0.039in x 0.043in).

 

BMP sensor operates over the I2C protocol. The input voltage range for BMP180 is from 1.8V to 3.6V.

BMP180 Pressure Sensor

We previously used the BMP180 sensor with Raspberry Pi and with ESP32 to build weather stations.

 

Ubidots Account Setup

Born as an engineering services firm in 2012, Ubidots delivered end-to-end IoT solutions in tandem with its partner and co-founding company Netux, to remotely monitor, control, and automate processes for healthcare clients.

 

Now, Ubidots has become popular as an affordable, reliable, and most usable platform for building an IoT application enabled ecosystem within hardware, software, and embedded engineering industry.

 

In this tutorial, we are sending the BMP sensor data to Ubidots over the HTTP protocol. To send the data, first create an account on Ubidots. After completing the account setup, click on the user dropdown menu and click API documentation. Make a note of your Default Token as it will be needed later.

Ubidots Account Setup

 

Programming NodeMCU for Ubidots

Program for Sending data to Ubidots is very easy as it only needs to read the BMP sensor data and send it to Ubidots over HTTP protocol.

 

Complete code is given at the end of the page. Here we are explaining important parts of the code.

 

So start your code by including all the required libraries. Adafruit_BMP085.h library is used to read the BMP sensor data while Ubidots.h is used to send data to the Ubidots platform over HTTP protocol.

#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "Ubidots.h"

 

After that, enter the token and Wi-Fi credentials to setup a connection between NodeMCU and Ubidots.

const char* UBIDOTS_TOKEN = "Your Ubidots Token";
const char* ssid     = "SSID Name"; // Your ssid
const char* password = "SSID Password"; // Your Password

 

Inside the void setup() function, initialize the baud rate and BMP180 using .begin() function, then connect the module with the Wi-Fi.

Serial.begin(115200);
  delay(100);
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  while (1) {}
  }
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println("WiFi is connected");

 

Now inside the void loop, read the temperature, pressure, and Altitude values from BMP180 Sensor and store these values in different variables. After that, send these readings to the Ubidots platform.

void loop() {
  float p = bmp.readPressure()/100;
  Serial.print("Pressure = ");
  Serial.print(p);
    float a = bmp.readAltitude();
  Serial.print("Altitude = ");
  Serial.print(a);
  float temperature = bmp.readTemperature();
  Serial.print("Temperature= ");
  Serial.print(temperature);
  ubidots.add("Temperature", temperature);// Change for your variable name 
  ubidots.add("Pressure", p);
  ubidots.add("Altitude", a);
  bool bufferSent = false;
  bufferSent = ubidots.send();

 

Testing the Ubidots with NodeMCU for BMP180 Sensor readings

Once your code and Hardware are ready, connect the NodeMCU to your laptop and upload the code. Now open the serial monitor to check if NodeMCU is reading the data or not.

Ubidots NodeMCU Code

 

After this, navigate to your browser and open the Ubidots Dashboard and click on the ‘Create Widget’ button, scroll down, and select the ‘Thermometer’ Widget.

Ubidots Setup

 

Now click on ‘Add Variables’ to select the device and variable.

Ubidots Working

 

Now select the device. Once you click on the device, you will see three variables, i.e. pressure, altitude, and temperature. Select the temperature variable.

Ubidots Dashboard

 

Then click on Finish. Repeat the same procedure for the Pressure and Altitude variables, but instead of selecting the Thermometer widget, select the ‘Gauge’ widget.

 

After finishing this process, your dashboard will look like this:

BMP Sensor Data Reading using Ubidots

This is how NodeMCU can be easily connected with Ubidots to present any sensor values graphically on the dashboard. And it can be monitored from anywhere in the world over the internet.

 

Complete code and demonstration video is given below.

Code

#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "Ubidots.h"
Adafruit_BMP085 bmp;
//WiFiClient client;
const char* UBIDOTS_TOKEN = "BBFF-waVbWAf7iT5hzDyXhlUdwqkoFiaF2K"; 
const char* ssid     = "....."; // Your ssid
const char* password = "......."; // Your Password
Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);

void setup() {
  Serial.begin(115200);
  delay(100);
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  while (1) {}
  }
ubidots.wifiConnect(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi is connected");
}
void loop() { 
  float p = bmp.readPressure()/100;
  Serial.print("Pressure = ");
  Serial.print(p);
  Serial.println(" mb");
  float a = bmp.readAltitude();
  Serial.print("Altitude = ");
  Serial.println(a);
  float temperature = bmp.readTemperature();
  Serial.print("Temperature= ");
  Serial.print(temperature);
  ubidots.add("Temperature", temperature);// Change for your variable name  
  ubidots.add("Pressure", p);
  ubidots.add("Altitude", a);
  bool bufferSent = false;
  bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id
  if (bufferSent) {
   Serial.println("Values sent by the device");
  }
  delay(3000);
}

Video

10 Comments

I'm just writing to make you be aware of of the superb encounter my cousin's child encountered reading your site. She picked up a lot of pieces, which include what it's like to have an amazing giving character to make the mediocre ones with no trouble grasp some advanced issues. You undoubtedly surpassed visitors' expectations. I appreciate you for supplying these beneficial, safe, informative and as well as unique tips about the topic to Sandra.

Thank you for your entire hard work on this site. Ellie take interest in working on research and it's obvious why. We all learn all of the compelling method you produce invaluable guides by means of this web site and as well as invigorate contribution from others on this content plus our daughter is always being taught a lot. Enjoy the rest of the new year. Your conducting a fantastic job.

I simply wanted to thank you so much again. I'm not certain the things I could possibly have undertaken in the absence of the type of pointers revealed by you relating to such a field. It was actually a real frustrating condition in my circumstances, but taking a look at your expert approach you solved the issue forced me to leap for fulfillment. I am happier for your assistance as well as hope that you are aware of a powerful job you happen to be getting into instructing the rest by way of a web site. I know that you have never encountered all of us.

I wish to express my love for your generosity in support of all those that really want help on this one field. Your very own dedication to passing the message around was rather important and have in every case allowed individuals just like me to achieve their ambitions. Your own warm and helpful guide signifies a whole lot a person like me and far more to my peers. Thanks a lot; from everyone of us.

I precisely needed to say thanks yet again. I'm not certain the things I could possibly have handled without the entire secrets shared by you about this situation. It seemed to be a real frightening issue in my view, nevertheless understanding the well-written way you solved it took me to leap for delight. I am just grateful for your service and sincerely hope you comprehend what a great job that you are undertaking instructing men and women using your webpage. I know that you've never got to know all of us.

I must express some appreciation to the writer just for rescuing me from this crisis. Right after checking throughout the online world and getting notions which are not productive, I figured my entire life was gone. Being alive without the solutions to the difficulties you have resolved all through your entire short article is a serious case, as well as the ones which might have badly damaged my career if I hadn't discovered your web site. Your skills and kindness in playing with everything was valuable. I don't know what I would've done if I had not encountered such a step like this. I can at this moment relish my future. Thanks for your time very much for this skilled and result oriented help. I will not be reluctant to propose the website to any person who needs to have tips about this subject.

Thanks for all of the work on this blog. Ellie take interest in making time for internet research and it's simple to grasp why. My spouse and i know all concerning the compelling method you present advantageous steps via your blog and in addition attract participation from some other people on the idea then our favorite child is truly learning a whole lot. Take pleasure in the rest of the new year. You are always carrying out a brilliant job.

Thanks a lot for giving everyone an exceptionally marvellous chance to read from this site. It is always so nice and also full of fun for me personally and my office mates to visit your blog nearly three times per week to learn the newest guidance you have got. And of course, I am at all times fascinated with your tremendous thoughts served by you. Some two facts in this posting are surely the most impressive we have had.

I have to show thanks to this writer for bailing me out of such a problem. As a result of researching through the the web and finding thoughts which are not beneficial, I believed my life was over. Existing minus the approaches to the difficulties you have fixed by means of the report is a critical case, as well as those that might have adversely affected my career if I had not come across your site. Your competence and kindness in taking care of all things was tremendous. I am not sure what I would have done if I had not come across such a subject like this. It's possible to at this time look ahead to my future. Thank you so much for the skilled and result oriented help. I won't be reluctant to endorse your site to anyone who would need guidelines on this problem.

Thank you so much for giving everyone such a memorable possiblity to read from this website. It's always very brilliant plus stuffed with a lot of fun for me personally and my office acquaintances to search your site at minimum three times in a week to find out the newest issues you will have. Not to mention, we are at all times fulfilled considering the breathtaking tricks you serve. Some two tips in this article are truly the very best I have had.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.