Introduction: IoT Made Simple: Monitoring Temperature Anywhere

About: Engineer, writer and forever student. Passionate to share knowledge of electronics with focus on IoT and robotics.

It's amazing how quickly you can put together an IoT protect using a NodeMCU and a Blynk app.

On this tutorial we will learn about a great, reliable and easy to use digital temperature sensor, the DS18B20. Also as shown at above block diagram, the collected data from the sensor will be upload to internet with a help of a NodeMCU ESP8266-E and monitored on a Smart device using the Blynk app.

Step 1: Bill of Material

Step 2: DS18B20 Temperature Sensor

We will use on this tutorial a waterproofed version of the DS18B20 sensor. It is very useful for remote temperature on wet conditions, for example on a humid soil. The sensor is isolated and can take measurements until 125oC (Adafrut does not recommend to use it over 100oC due its cable PVC jacket.

The DS18B20 is a digital sensor what makes it good to use even over long distances! These 1-wire digital temperature sensors are fairly precise (±0.5°C over much of the range) and can give up to 12 bits of precision from the onboard digital-to-analog converter. They work great with the NodeMCU using a single digital pin, and you can even connect multiple ones to the same pin, each one has a unique 64-bit ID burned in at the factory to differentiate them.

The sensor works from 3.0 to 5.0V, what means that it can be powered directly from one of the 3.3V NodeMCU pins.

The sensor has 3 wires:

  • Black: GND
  • Red: VCC
  • Yellow: 1-Wire Data

Here, you can find the full data: DS18B20 Datasheet

Step 3: Connecting the Sensor to NodeMCU

  1. Connect the 3 wires from sensor at the mini Breadboard as shown at the above photo. Pay carefully attention where the NodeMCU pins will be inserted.
    • Red ==> 3.3V
    • Black ==> GND
    • Yellow ==> D4
  2. Insert the NodeMCU, on a way that its pins will match with the above electrical diagram. Note that pressing the chip over the sensor cable, will will help to keep the sensor contacts on place.
  3. Insert the 4.7K ohms resistor between VCC (3.3V) and Data (D4)

Step 4: Installing the Appropriated Libraries

In order to use the DS18B20 properly, two libraries will be necessary:

  1. OneWire
  2. DallasTemperature

Install both libraries in your Arduino IDE Library depository.

Note that the OneWire library MUST be the special one, modified to be used with ESP8266, otherwise you will get an error during compilation. You will find the last version at above link or from the bellow zip file:

Step 5: Testing the Sensor

For testing the sensor, you can use the code "Simple.ino" included on the Library Examples, as shown at the photo.

Upload the code in your NodeMCU and monitor the temperature using the Serial Monitor. The above photo shows the expected result. Hold the sensor in your hand, you should see the temperature going to circa of 32/34oC.

Step 6: Using Blynk

Once you start capturing temperature data, its time to see it from anywhere. We will get this using Blynk. So, all captured data will be displayed on real time on your mobile device and also we will build an historical depository for that.

Follow the bellow steps:

  1. Create a New Project.
  2. Give it a name (in my case "Temperature Sensor")
  3. Select NodeMCU as HW Model
  4. Copy the AUTH TOKEN to be used in the code (you can send it to your email).
  5. Includes a "Gauge" Widget, defining:
    • Virtual pin to be used with the sensor: V10
    • The temperature range: -10 to 100 oC
    • The frequency to read data: 1second
  6. Includes a "History Graph" Widget, defining V10 as virtual pin
  7. Press "Play" (The triangle at right up corner)

Of course, the Blynk App will tel you that the NodeMCU is off line. It's time to upload the full code at your Arduino IDE:

 * IoT Temperature Monitor with Blynk
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 * Developed by Marcelo Rovai - 05 January 2017

/* ESP & Blynk */
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
char auth[] = "YOUR AUTH CODE HERE";

/* WiFi credentials */
char ssid[] = "YOUR SSID";
char pass[] = "YOUR PASSWORD";

/* TIMER */
SimpleTimer timer;

/* DS18B20 Temperature Sensor */
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;

void setup() 
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, getSendData);

void loop() 
{; // Initiates SimpleTimer;

 * Send Sensor data to Blynk
void getSendData()
  temp = DS18B20.getTempCByIndex(0);
  Blynk.virtualWrite(10, temp); //virtual pin V10

Once the code is uploaded and running, check the BLYNK app. It should be now also running.

Bellow the full Arduino code for your project:

Step 7: Conclusion

As always, I hope this project can help others find their way in the exciting world of electronics and IoT!

For more projects, please visit my blog:

Saludos from the south of the world!

See you at my next instructable!

Thank you


Arduino Contest 2016

Participated in the
Arduino Contest 2016

Epilog Contest 8

Participated in the
Epilog Contest 8