Temperature Control With Ubidots MQTT and NodeMcu




Introduction: Temperature Control With Ubidots MQTT and NodeMcu

This guide details how to make a temperature control with Ubidots. In addition, we'll show you how to create different events that notify you through email or SMS when your "variable" (in this case, the temperature) changes its value.

We are going to use a pre-wired and waterproof version of the DS18B20 sensor (OneWire temperature sensor). It's handy when you need to measure something far away, or in wet conditions. The OneWire temperature sensor has different versions; one of them has a resistor integrated and others don't, so make sure the version you're using is correct before starting with the project. For the control we are going to use a NodeMcu using a digital pin.

Step 1: Requirements

Step 2: Setup

1. First, we should choose a version. If your sensor has the resistor integrated, just connect it to the NodeMcu like this:




If not, you have to power the DATA pin through the resistance of 4.7kΩ, and the Vin and GND pins should be connected to each other and the ground.

2. Go to the Arduino IDE, click on Files -> Preferences, and enter http://arduino.esp8266.com/stable/package_esp8266... into the "Additional Board Manager URLs" field. You can add multiple URLs, separating them with commas.

3. Open "Boards Manager" from Tools -> Board menu and install esp8266 platform (and don’t forget to select your NodeMCU 1.0 board from the Tools > Board menu after installation).

4. Download the UbidotsESPMQTT library, OneWire Library, and DallasTemperature Library using these hyperlinks.

5. Now, click on Sketch -> Include Library -> Add .ZIP Library.

6. Select the .ZIP files of Ubidots ESPMQTT, OneWire, and DallasTemperature and then “Accept” or “Choose” for all the libraries. If you can't add the libraries, try manually: unzip the downloaded rar/zip and copy the folder from the library to the path C:\Users\ubidots\Documents\Arduino\libraries.

7. Close the Arduino IDE and open it again.

Step 3: Program the ESP NodeMcu

Once everything is connected correctly, we will go to the IDE and write the following code: click here

Step 4: Results

Now, open your Ubidots account and go to Source. You will see a new DataSource named "control". click on it.

Then, you will see the temperature value.

Step 5: Events

Also, you can create an Event that notifies you when temperature is irregular. Go to Events, click on Add Event, and select your Data Source and Variable.

The Events can notify you via email, sms, Telegram, or WebHook. You can also set a variable.

When your event is ready you should see these windows

In this example, if temperature value is >= 28, Ubidots will send you an email as previously configured, as such:

It's very simple! With just few cables you can observe the temperature behavior of your home, whether you're inside or outside. You can even trigger alerts via email/SMS in case of fire.

Now you try! If you haven't signed up with Ubidots, go here

Be the First to Share


    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Chocolate Challenge

      Chocolate Challenge
    • Home and Garden Contest

      Home and Garden Contest



    Question 2 months ago

    i am tryin to add NodeMCU to Ubidots but i cannot find in device list.


    4 years ago


    You can reference to this example(https://github.com/ubidots/ubidots-mqtt-esp/blob/master/examples/subscribe_and_publish/subscribe_and_publish.ino), this example will serve you to publish and subscribe to/from Ubidots.

    Modify the example above with your parameters, also with the example provided in the project. To give you a better idea, you have to publish the temperature value and subscribe it to a new variable(the fan), this variable have to be create before upload the code into the device. Then, you can use the Ubidots Events as we did it in the project but instead of "send a e-mail" select "Set a variable" and select the variable that you subscribed it (the fan). So, when the temperature reaches the limit, set the value "1" in order to turn on the fan, then follow the same process to create a other event in order to turn off the fan.

    I hope this would help you :)

    All the best,

    Maria C.


    4 years ago

    i has made this project and successful .

    but i try to add relay to trigger 12dc fan in automation (condition = fan on when temp >31 , unfortunately i cant modified the coding .

    this will be the very benefical in my learning of coding in arduino .. thanks .