DS18B20 Temperature Sensor with ESP32



Discover the future of temperature monitoring with the DS18B20 sensor and ESP32 duo! In our latest blog, we delve into the dynamic world of IoT-enabled temperature tracking. Uncover the myriad benefits and features of this powerful sensor combination, and unlock the true potential of ThingSpeak. From real-time data visualization to seamless integration, learn how ThingSpeak empowers you to harness the full spectrum of temperature insights. Dive in today and revolutionize your approach to monitoring with a single click!


In this blog, we will learn how to interface the DS18b20 sensor with an ESP32 and also learn about Thingspeak. ThingSpeak™ is an IoT analytics platform service that allows you to aggregate, visualize, and analyze live data streams on the cloud. You can send data to ThingSpeak from your devices, create instant visualizations of live data, and send alerts using web services like Twitter® and Twilio®. With MATLAB® analytics inside ThingSpeak, you can write and execute MATLAB code to perform preprocessing, visualizations, and analyses. ThingSpeak enables engineers and scientists to prototype and build IoT systems without setting up servers or developing web software.

Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area.




Benefits and Features:


  • Unique 1-Wire® Interface Requires Only One Port Pin for Communication
  • Reduce Component Count with Integrated Temperature Sensor and EEPROM
  • Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
  • ±0.5°C Accuracy from -10°C to +85°C.
  • Programmable Resolution from 9 Bits to 12 Bits
  • Parasitic Power Mode Requires Only 2 Pins for Operation (DQ and GND)
  • Simplifies Distributed Temperature-Sensing Applications with Multidrop Capability
  • Each Device Has a Unique 64-Bit Serial Code Stored in On-Board ROM
  • Flexible User-Definable Nonvolatile (NV) Alarm Settings with Alarm Search Command Identifies Devices with Temperatures Outside Programmed Limits.

Key capabilities of ThingSpeak include:


  • Configure devices to send data to ThingSpeak using a REST API or MQTT.
  • Aggregate data on-demand from devices and third-party sources.
  • Get instant visualizations of live or historical sensor data.
  • Preprocess and analyze your collected data using integrated MATLAB.
  • Run your IoT analytics automatically based on schedules or events.
  • Act on your data and communicate using third-party services like Twilio or Twitter.


We start off by making a thingspeak account. Head over to https://thingspeak.com and create your account. A verification mail will be sent to your registered mail ID. Once you verify, thingspeak will redirect you to create a MathWorks account as well as thingspeak uses MATLAB for analysis. Once your MathWorks account is also created, you can log in to the thingspeak account and create a channel where the temperature data from the DS18b20 will be logged and can be accessed anytime.


After you log in, you can see a “Create New Channel” option pop up on the screen. You will have to fill out the following data about the channel.


Fill out the Channel Settings page and click on save channel at the bottom of the page to create the channel. You can refer to the below-mentioned points if you have a doubt regarding the details to be filled out.


  • Channel Name *: Enter a unique name for the ThingSpeak channel.
  • Description *: Enter a description of the ThingSpeak channel.
  • Field# *: Check the box to enable the field, and enter a field name. Each ThingSpeak channel can have up to 8 fields.
  • Metadata: Enter information about channel data, including JSON, XML, or CSV data.
  • Tags: Enter keywords that identify the channel. Separate tags with commas.
  • Link to External Site: If you have a website that contains information about your ThingSpeak channel, specify the URL.
  • Show Channel Location:
  • Latitude: Specify the latitude position in decimal degrees. For example, the latitude of the city of London is 51.5072.
  • Longitude: Specify the longitude position in decimal degrees. For example, the longitude of the city of London is -0.1275.
  • Elevation: Specify the elevation position meters. For example, the elevation of the city of London is 35.052.
  • Video URL: If you have a YouTube or Vimeo video that displays your channel information, specify the full path of the video URL.
  • Link to GitHub: If you store your ThingSpeak code on GitHub, specify the GitHub repository URL.


Mandatory fields to fill:


Once the channel is created, click on the API Keys tab and make a note of the “Channel ID” and “Write API Key”. An interesting feature of thingspeak is that the data saved on the Cloud can be accessed by Android and IOS applications. One such application is called PocketIOT. Install this app from the play store and with the help of the channel details such as Channel ID and Read API Key, you can monitor the stored data on your phone anytime.

You can download the android application from the following link: https://play.google.com/store/apps/details?id=com.buzsikdev.pocketiot&hl=en

The hardware connections for the DS18b20 sensor are pretty straightforward. There are 3 wires coming out of the sensor, Vcc, GND, and Data. The sensor works best in the following configuration:

  • Vcc 3.3V(in this case powered through an ESP32)
  • GND ( common ground provided to both ESP32 and Arduino)
  • Data line connected to a 5V source through a 10k resistor(in this case powered through the Arduino)
  • Through the Arduino IDE upload the following code to the ESP32. This code will read the temperature value from the sensor continuously and publish this value to thingspeak at an interval of 2 seconds.


You can download the thingspeak library from the following link: https://github.com/mathworks/thingspeak-arduino

The code used in this example has been uploaded to our GitHub account: https://github.com/Robocraze/DS18B20



As we conclude this exciting journey into the realm of temperature sensing and IoT innovation, it's clear that the DS18B20 sensor paired with the ESP32 opens a world of possibilities. From accurate temperature readings to seamless connectivity, this dynamic duo offers unparalleled benefits. But that's not all – with ThingSpeak's key capabilities, you can effortlessly transform raw data into meaningful insights, all in real-time. Imagine the potential for industries ranging from agriculture to healthcare. Ready to take the plunge into smarter, data-driven decision-making? Embrace the future with DS18B20, ESP32, and ThingSpeak today! Your next level of temperature monitoring awaits – don't miss out!


Components and Supplies

You may also like to read

Frequently Asked Questions

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.

Components and Supplies

You may also like to read