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 HTTPS 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.
Hardware requirements
- NODEMCU
- DHT11 Sensor
- Led
- Bread Board
Software Requirements
Circuit Configuration
NODEMCU | |
D4 | S (DHT11) |
D2 | led (Anode) |
Gnd | Led(Cathode) |
3V3 | 3.3V |
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
2. So now choose Ubidots stem for free account
3. Following, select API Credentials and copy the Token
4. Then select Devices and add a new device
5. In addition to it click on your device and then add variables required as per project requirement. Finally saving it.
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
8. Likewise, add a new dashboard and complete the required general information
9. Finally, now add widgets and select the required variable, range, and style, etc
10. Include Ubidots library from here.
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 HTTPS protocol thus it’s necessary to include all necessary API token, Device names, and Variable names.
#include "Ubidots.h"
#include <dht.h>
const char* UBIDOTS_TOKEN = "......."; // Put here your Ubidots TOKEN
const char* WIFI_SSID = "...."; // Put here your Wi-Fi SSID
const char* WIFI_PASS = "...."; // Put here your Wi-Fi password
#define DHT11_PIN 2//D4
#define LED_PIN 0//D3
dht DHT;
Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);
float value=0;
void setup()
{
pinMode(LED_PIN,OUTPUT);
Serial.begin(115200);
ubidots.wifiConnect(WIFI_SSID, WIFI_PASS);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
float value = ubidots.get(".....", "led");//Paste your API label, Variable name
if (value != ERROR_VALUE)
{
Serial.print("Value:");
Serial.println(value);
}
if(value == 0.00)
{
Serial.println("Light1 turned off");
digitalWrite(LED_PIN, LOW);
}
if(value == 1.00)
{
Serial.println("Light1 turned ON");
digitalWrite(LED_PIN, HIGH);
}
ubidots.add("Temperature",DHT.temperature);//or your variable name
ubidots.add("Humidity",DHT.humidity);
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(10);
}
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.
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.