It's amazing how quickly you can put together an IoT project using a NodeMCU and a Blynk app.
In this tutorial, we will learn about a great, reliable and easy-to-use digital temperature sensor, the DS18B20. Also, as shown in the above block diagram, the collected data from the sensor will be uploaded to internet with the help of a NodeMCU ESP8266-E and monitored on a smart device using the Blynk app.
Step 1: Bill of Material- Resistor 4.7K Ohms
We will use a waterproofed version of the DS18B20 sensor. It is very useful for remote temperature in wet conditions like humid soil, for example. The sensor is isolated and can take measurements up to 125°C (Adafruit does not recommend its use over 100°C due its cable PVC jacket)
The DS18B20 is a digital sensor which 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 - 5.0V, which 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 NodeMCUConnect the 3 wires from sensor to the mini-breadboard as shown in the above photo. Pay careful attention to where the NodeMCU pins will be inserted.
- Red ==> 3.3V
- Black ==> GND
- Yellow ==> D4
Insert the NodeMCU in a way that its pins will match with the above electrical diagram. Note that pressing the chip over the sensor cable will help to keep the sensor contacts in place. And insert the 4.7K ohms resistor between VCC (3.3V) and data (D4).
Step 4: Installing the appropriated librariesIn order to use the DS18B20 properly, two libraries will be necessary:
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 latest version via the above link or from the bellow zip file:
Step 5: Testing the sensorFor 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. Holding the sensor in your hand, you should see the temperature going to about 32/34°C.
Step 6: Using BlynkOnce 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 a historical depository for that.
Follow the below steps:
Create a New Project.
- Give it a name (in my case "Temperature Sensor")
- Select NodeMCU as HW Model
- Copy the AUTH TOKEN to be used in the code (you can send it to your email).
Includes a "Gauge" Widget, defining:
- Virtual pin to be used with the sensor: V10
- The temperature range: -10 to 100°C
- The frequency to read data: 1 second
Includes a "History Graph" Widget,
- Define V10 as virtual pin
Press "Play" (The triangle at right up corner)
Of course, the Blynk App will tell you that the NodeMCU is offline. It's time to upload the full code to your Arduino IDE. Once the code is uploaded and running, check the BLYNK app. It should be running now also. Just below is the full Arduino code for your project (also in the Code section):
Step 7: ConclusionAs 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 tutorial!
Thank you
Marcelo
Comments