Introduction: IoT Made Simple: Monitoring Temperature Anywhere

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 */
#include 
#include 
#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 */
#include 
SimpleTimer timer;

/* DS18B20 Temperature Sensor */
#include 
#include 
#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() 
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  DS18B20.begin();
  timer.setInterval(1000L, getSendData);
}

void loop() 
{
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}

/***************************************************
 * Send Sensor data to Blynk
 **************************************************/
void getSendData()
{
  DS18B20.requestTemperatures(); 
  temp = DS18B20.getTempCByIndex(0);
  Serial.println(temp);
  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: MJRoBot.org

Saludos from the south of the world!

See you at my next instructable!

Thank you

Marcelo

Comments

author
TruthS3 (author)2017-07-28

Hello.

Is there a wiring diagram for how to make the correct resistance when using more than one sensor?

author
dBuggz (author)TruthS32017-08-29

The resistor does not need to be changed. It is just used as a 'pullup' on the data line.

author
TruthS3 (author)2017-08-24

Hello Marcelo, Now that I have a working project would you be willing to help me do two things?

1. I want the readings in Fahrenheit

2. I would like to connect the second sensor and have it show in Blynk.

If you don't, I understand, but please tell me.

I've got two weeks to get this going for freezer monitoring while we are away. That's why I sought help at the community, Getting the parts took longer than I expected and while I read both parts of your pj. I got jammed up and desperate for help with the complexity. Fortunately, there I was able to find a helper who stayed online with me for an hour to get it all sorted. But this is your pj and I do appreciate it and I would like to finish off this last bit with your help.

author
mjrovai (author)TruthS32017-08-25

Please see my new tutorial, exploring multiple sensors:

https://www.instructables.com/id/IoT-Made-Simple-M...

Thanks

author
TruthS3 (author)mjrovai2017-08-25

Went there and printed the whole thing to read, I'm so old I do much better with a piece of paper in my hand. BTW I cleaned up a lot of my posts that were not meaningful, trying not to clutter your Instr.

author
mjrovai (author)TruthS32017-08-25

You must use 2 indexes for sensor readings:

temp_0 = DS18B20.getTempFByIndex(0)

temp_1 = DS18B20.getTempFByIndex(1)

Multiple_DS1B20.png
author
mjrovai made it! (author)mjrovai2017-08-25

Bellow the Electrical diagram from my test

Electrical Diagram 2.png
author
mjrovai (author)2017-08-25

Please see my new tutorial, exploring multiple sensors:

https://www.instructables.com/id/IoT-Made-Simple-M...

Thanks

author
mjrovai made it! (author)2017-08-25

If you can use 2 sensors and data in Fahrenheit, use the general test code below.

The photo shows 2 DS18B20 connected to NodeMCU Pin 4:

The Serial Monitor shows the data changed on sensors when I covered one by one with my hand.

Test_Code.pngDual DS18B20.JPGSerial Monitor Dual Sensor.png
author
TruthS3 (author)2017-08-24

May I guess that I will get F if I change the C below to F?

DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.println(temp);
Blynk.virtualWrite(10, temp); //virtual pin V10

author
mjrovai (author)TruthS32017-08-25

Yes, you can do it:

temp = DS18B20.getTempFByIndex(0);

For your knoledge, according to DS18B20 Datasheet, (http://datasheets.maximintegrated.com/en/ds/DS18B2... it is a digital thermometer provides 9-bit to 12-bit Celsius temperature measurements. So, you can use the internal library function or you can easily convert the measured data using the below formula, your choice:

Ftemp = (temp * 9.0)/ 5.0 + 32.0;

author
TruthS3 (author)2017-08-25

should I have also modified the float to be float_f ?

author
TruthS3 (author)2017-08-24

I went over to the Blynk community and got much needed help there. For other noobs:

1. make sure you have proper drivers in your pc

2.make sure you have esp8266 in IDE

3.Steps 1-5 are all just practice they have no relation to what you must enter in IDE to get Blynk going.

4. The Blynk community said the code as presented here will not work as a copy/paste, they reworked it:

/**************************************************************
* 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 */
#include
#include
#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 */
//#include // NOT REQUIRED WITH BLYNK LIBRARY VERSION 0.4.8 AND BEYOND
BlynkTimer timer;

/* DS18B20 Temperature Sensor */
#include
#include
#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()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
DS18B20.begin();
timer.setInterval(1000L, getSendData);
}

void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
}

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

You might have to go there to copy it again :

https://community.blynk.cc/t/noob-needs-help-with-...

You must clear out all the writing in the code space on your new project before pasting this corrected code.

Works Great, Now to figure out how to get two temps going!

author
TruthS3 (author)2017-08-23

Hello Marcello,

I'm really having trouble, I'd really like to complete this but I feel stupid, I try to follow your instructions and I'm banging my head on the wall.

I don't understand upload the blynk file to Arduino. Could you please be more detailed about the steps involved.

I would really appreciate your help.

author
mjrovai (author)TruthS32017-08-24

Hi.

1. You must have the .ino (Arduino type file that you will download from my GitHub or just clicking on the link: TempMonBlynkExt.ino) inside a directory with same name.

2. You must open the .ino file on your Arduino IDE (that must have been previously set-up for NodeMCU V1.0)

3. You must enter with your home wifi credentials

4. You must enter with your "Blynk Authorization code", that you got when you create the Blynk App.

5. Compile and Upload the final .ino code in your NodeMCU

6. Open your Blynk App.

I believe that's is it.

Maybe you should follow my below tutorial, that was my first one with NodeMCU/Blynk. I entered in more details there:

https://www.instructables.com/id/From-Blink-to-Bly...

Thanks

Marcelo

author
mjrovai (author)2017-07-28

If you want to connect multiple sensors, please take a look on the above tutorial. It is great. Thanks
http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#mult

IMG_2325.PNG
author
gegerio (author)2017-01-06

Grande trabalho cara !!!

author
mjrovai (author)gegerio2017-01-06

Valeu! Muito obrigado!
Também publiquei hoje em meu blog em português
https://mjrobot.org/2017/01/06/o-iot-feito-simples-monitorando-a-temperatura-desde-qualquer-lugar/
Está um pouco melhor formatado.
Um abraço

About This Instructable

6,566views

132favorites

License:

Bio: Engineer, writer and forever student. Passionate to share knowledge of electronics with focus on IoT and robotics.
More by mjrovai:ESP32 and OLED Display: Internet Clock - DHT22 IOT Made Simple: Playing With the ESP32 on Arduino IDEIoT Made Simple: Monitoring Multiple Sensors
Add instructable to: