IoT Made Simple: Monitoring Temperature Anywhere

34K16824

Intro: 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

16 Comments

thank you for a very instructive project, would have been helpful to include "install Blynk library"
I have the project up and working with a few niggles;

1, temperature is displaying as 42.8 oC yet the temp is 26.5 0C can this be calibrated some way
2. Is there anyway that the Blynk gauge can be modified to look better

Thank you once again



im very newbe in arduino, and very interestic to know and try, until this step i got problem, what mean onewire have to modified?
because, i was go to step 4, test witl dallas, use monitor its work, but, when i upload last step, its cannot upload, the messeges was cannot find wifi directory skecth on.......

can help me please?

Hello.

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

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

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

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;

should I have also modified the float to be float_f ?

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!

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.

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

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

Grande trabalho cara !!!

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