All you need to know about integrating NodeMCU with Ubidots over MQTT

by Jun 2, 2021Projects

In this tutorial, let’s discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be over MQTT protocol.

Introduction to Ubidots

Ubidots value-add in development time and cost saved is only increased when combined with its usability. Thus with a core architecture focused on data efficiency and an engaging UX (user experience), users can connect, build, and deploy cloud IoT applications with ease, leavings it to handle the cloud and end-user UX infrastructure.

Introduction to MQTT

The MQTT known as the Message Queuing Telemetry Transport) is a light weight publish/subscribe protocol designed for M2M (Machine to Machine) telemetry in low bandwidth environments.

Hardware requirements

  1. NODEMCU
  2. DHT11 Sensor
  3. Led
  4. Bread Board

Software Requirements

  1. Arduino IDE

Circuit Configuration

This image has an empty alt attribute; its file name is image-13.png
Interfacing DHT11 and led with NodeMCU
NODEMCU
D4S (DHT11)
D2led (Anode)
GndLed(Cathode)
3V3vcc(DHT11)
Pin Diagram

Programming NodeMCU in Arduino IDE

In order to code NodeMCU in Arduino IDE follow these steps .

Configuration of Ubidots

1.Firstly, Create an account here

This image has an empty alt attribute; its file name is Screenshot-102.png
Create an account and sign up

2. So now choose Ubidots stem for free account

This image has an empty alt attribute; its file name is Screenshot-116-1-1024x702.png
select ubidots stem

3. Following, select API Credentials and copy the Token

This image has an empty alt attribute; its file name is Screenshot-107-1024x460.png
Copy the token

4. Then select Devices and add a new device

Give a name to your device(IOTEDU1)

5. In addition to it click on your device and then add variables required as per project requirement. Finally saving it.

Add the required variables clicking on ‘+’

6. Similarly copy API label in above step if you are receiving data from ubidots cloud

7. Now, go back and select data then choose dashboard

This image has an empty alt attribute; its file name is Screenshot-118.png
Select dashboard

8. Likewise, add a new dashboard and complete the required general information

Complete general information and save

9. Finally, now add widgets and select the required variable, range, and style, etc

Add widgets as per requirement

10. Include Ubidots library from here. Along with it include pubsubclient library as well.

11. Lastly run the code, by pasting all necessary tokens, API labels, and variable names. Notice the parameters in the dashboard.

Code

The code below integrates NodeMcu with ubidots over MQTT protocol thus it’s necessary to include all necessary API token, Device names, and Variable names.

#include "UbidotsESPMQTT.h"
#include <dht.h>

#define TOKEN "........." // Your Ubidots TOKEN
#define WIFINAME ".........." //Your SSID
#define WIFIPASS "........."// Your Wifi Pass
#define DHT11_PIN 2//D4
#define LED_PIN 0//D3

dht DHT;
Ubidots client(TOKEN);

#define DEVICE_LABEL  "iotedu1"  // Put here your Ubidots device label
#define VARIABLE_LABEL  "led1"  // Put here your Ubidots variable label 


void callback(char* topic, byte* payload, unsigned int length)
 {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) 
  {
    Serial.print((char)payload[i]);
  }
  Serial.println();
  if ((char)payload[0]=='1')
  {
    digitalWrite(LED_PIN, HIGH);
  }
   else if ((char)payload[0]=='0')
  {
    digitalWrite(LED_PIN, LOW);
  } 
}


void setup()
 {
  client.setDebug(true); // Pass a true or false bool value to activate debug messages
  Serial.begin(115200);
  client.wifiConnection(WIFINAME, WIFIPASS);
  client.begin(callback);
  pinMode(LED_PIN,OUTPUT);
  client.ubidotsSubscribe(DEVICE_LABEL, VARIABLE_LABEL);//subscribe to the topic
 }

void loop() 
{
  if(!client.connected())
      {
      client.reconnect();
      }
  client.ubidotsSubscribe(DEVICE_LABEL, VARIABLE_LABEL); 
  int chk = DHT.read11(DHT11_PIN);
   
  client.add("temperature", DHT.temperature);
  client.add("Humidity", DHT.humidity);
  client.ubidotsPublish("IOTEDU1");
  client.loop();
  delay(100);
  }

Result

Thus, we can observe that the data sent from Arduino noted in the serial monitor and the dashboard parameters appears to be the same.

Parameters displayed
Data viewed in serial monitor
This image has an empty alt attribute; its file name is WhatsApp-Image-2021-05-02-at-1.25.06-PM-1024x768.jpeg

Summary

Thus, we learned how to use NodeMCU with ubidots illustrating with an example of monitoring temperature and Humidity. In addition to it, we have controlled the led bulb from Ubidots dashboard using MQTT protocol.

Creating a multiplication Skill in Alexa using python

Written By Monisha Macharla

Hi, I'm Monisha. I am a tech blogger and a hobbyist. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning!

RELATED POSTS

How to Simulate IoT projects using Cisco Packet Tracer

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

How to design a Wireless Blind Stick using  nRF24L01 Module?

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

How to implement Machine Learning on IoT based Data?

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....

How to build a Safety Monitoring System for COVID-19

How to build a Safety Monitoring System for COVID-19

It is expected that the world will need to battle the COVID-19 pandemic with precautious measures until an effective vaccine is developed. This project proposes a real-time safety monitoring system for COVID-19. The proposed system would employ an Internet of Things...

Air Quality Monitoring using NodeMCU and MQ2 Sensor – IoT

Air Quality Monitoring using NodeMCU and MQ2 Sensor – IoT

There have been many incidents like explosions and fire due to certain gases leakage. Such incidents can cause dangerous effects if the leakage is not detected at an early stage. Therefore, Measurement and control of these types of toxic gases present in the...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....