ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (2023)

This is a in-depth guide for the DS18B20 temperature sensor with ESP8266 using Arduino IDE. We’ll cover how to wire the sensor, install the required libraries, and write the code to get the sensor readings from one and multiple sensors. Finally, we’ll build a simple web server to display the sensor readings.

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (1)

Throughout this tutorial we’ll cover the following topics:

  1. Read temperature from one DS18B20 temperature sensor;
  2. Read temperature from multiple DS18B20 temperature sensors;
  3. Display DS18B20 sensor readings on a web server.

You might also like reading other DS18B20 guides:

  • ESP32 DS18B20 Temperature Sensor with Arduino IDE
  • ESP32/ESP8266 DS18B20 Temperature Sensor with MicroPython
  • ESP32 with Multiple DS18B20 Temperature Sensors
  • DS18B20 Temperature Sensor with Arduino

Learn more about the ESP8266 with our course:Home Automation using ESP8266.

Introducing DS18B20 Temperature Sensor

TheDS18B20 temperature sensoris a one-wire digital temperature sensor. This means that it just requires one data line (and GND) to communicate with your ESP8266.

It can be powered by an external power supply or it can derive power from the data line (called “parasite mode”), which eliminates the need for an external power supply.

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (2)

Each DS18B20 temperature sensor has a unique 64-bit serial code. This allows you to wire multiple sensors to the same data wire. So, you can get temperature from multiple sensors using just one GPIO.

The DS18B20 temperature sensor is also available inwaterproof version.

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (3)

Here’s a summary of the most relevant specs of the DS18B20 temperature sensor:

  • Communicates over one-wire bus
  • Power supply range: 3.0V to 5.5V
  • Operating temperature range: -55ºC to +125ºC
  • Accuracy +/-0.5 ºC (between the range -10ºC to 85ºC)

For more information consult theDS18B20 datasheet.

Parts Required

To complete this tutorial you need the following components:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (4)

ESP8266 with DS18B20 Schematic Diagram

As mentioned previously, the DS18B20 temperature sensor can be powered through the VDD pin (normal mode), or it can derive its power from the data line (parasite mode). You can choose either modes.

Parasite Mode

Normal Mode

Note:in this tutorial we’re connecting the DS18B20 data line to GPIO 4, but you can use any other suitable GPIO.

Read ourESP8266 GPIO Reference Guideto learn more about the ESP8266 GPIOs.

(Video) ESP32 DHT11/DHT22 Asynchronous Web Server (auto updates Temperature and Humidity)

Note: if you’re using an ESP-01,GPIO 2is the most suitable pin to connect to the DS18B20 data pin.

Preparing Your Arduino IDE

We’ll program the ESP8266 using Arduino IDE, so make sure you have the ESP8266 add-on installed before proceeding:

  • Install ESP8266 Board in Arduino IDE (Windows, Mac OS X, and Linux instructions)

Installing Libraries for DS18B20

To interface with the DS18B20 temperature sensor, you need to install theOne Wire library by Paul Stoffregenand theDallas Temperature library. Follow the next steps to install those libraries.

1. Open your Arduino IDE and go toSketch>Include Library>Manage Libraries. The Library Manager should open.

2. Type “onewire” in the search box and install the OneWire library by Paul Stoffregen.

3. Then, search for “Dallas” and install the Dallas Temperature library by Miles Burton.

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (8)

After installing the libraries, restart your Arduino IDE.

Code (Single DS18B20)

After installing the required libraries, you can upload the following code to the ESP8266. The code reads temperature from the DS18B20 temperature sensor and displays the readings on the Arduino IDE Serial Monitor.

/********* Rui Santos Complete project details at https://RandomNerdTutorials.com *********/#include <OneWire.h>#include <DallasTemperature.h>// GPIO where the DS18B20 is connected toconst int oneWireBus = 4; // Setup a oneWire instance to communicate with any OneWire devicesOneWire oneWire(oneWireBus);// Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire);void setup() { // Start the Serial Monitor Serial.begin(115200); // Start the DS18B20 sensor sensors.begin();}void loop() { sensors.requestTemperatures(); float temperatureC = sensors.getTempCByIndex(0); float temperatureF = sensors.getTempFByIndex(0); Serial.print(temperatureC); Serial.println("ºC"); Serial.print(temperatureF); Serial.println("ºF"); delay(5000);}

View raw code

There are many different ways to get the temperature from DS18B20 temperature sensors. However, if you’re using just one single sensor, this is one of the easiest and simplest ways.

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (9)

How the Code Works

Start by including the OneWire and the DallasTemperature libraries.

#include <OneWire.h>#include <DallasTemperature.h>

Create the instances needed for the temperature sensor. The temperature sensor is connected to GPIO 4.

// GPIO where the DS18B20 is connected toconst int oneWireBus = 4;// Setup a oneWire instance to communicate with any OneWire devicesOneWire oneWire(oneWireBus);// Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire);

In the setup(), initialize the Serial Monitor at a baud rate of 115200.

Serial.begin(115200);

Initialize the DS18B20 temperature sensor:

sensors.begin();

Before actually getting the temperature, you need to call the requestTemperatures() method.

sensors.requestTemperatures(); 

Then, get the temperature in Celsius by using the getTempCByIndex() method as shown below:

float temperatureC = sensors.getTempCByIndex(0);

Or use the getTempFByIndex() to get the temperature in Fahrenheit.

float temperatureF = sensors.getTempFByIndex(0);

The getTempCByIndex() and the getTempFByIndex() methods accept the index of the temperature sensor. Because we’re using just one sensor its index is 0. If you want to read more than one sensor, you use index 0 for one sensor, index 1 for other sensor and so on.

(Video) Episode 2: MicroPython on ESP32 - Interfacing OLED Display, DS18B20 Sensor & Creating Web Server

Finally, print the results in the Serial Monitor.

Serial.print(temperatureC);Serial.println("ºC");Serial.print(temperatureF);Serial.println("ºF");

New temperature readings are requested every 5 seconds.

delay(5000);

Demonstration

After uploading the code, open the Arduino IDE Serial Monitorat a 9600 baud rate. You should get the temperature displayed in both Celsius and Fahrenheit:

Getting Temperature from Multiple DS18B20 Temperature Sensors

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (11)

The DS18B20 temperature sensor communicates using one-wire protocol and each sensor has a unique 64-bit serial code, so you can read the temperature from multiple sensors using just one single digital Pin.

Schematic

To read the temperature from multiple sensors, you just need to wire all data lines together as shown in the next schematic diagram:

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (12)

Code (Multiple DS18B20s)

Then, upload the following code. It scans for all devices on GPIO 4 and prints the temperature for each one. This sketch is based on the example provided by the DallasTemperature library.

/********* Rui Santos Complete project details at https://RandomNerdTutorials.com *********/#include <OneWire.h>#include <DallasTemperature.h>// Data wire is plugged TO GPIO 4#define ONE_WIRE_BUS 4// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)OneWire oneWire(ONE_WIRE_BUS);// Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire);// Number of temperature devices foundint numberOfDevices;// We'll use this variable to store a found device addressDeviceAddress tempDeviceAddress; void setup(){ // start serial port Serial.begin(115200); // Start up the library sensors.begin(); // Grab a count of devices on the wire numberOfDevices = sensors.getDeviceCount(); // locate devices on the bus Serial.print("Locating devices..."); Serial.print("Found "); Serial.print(numberOfDevices, DEC); Serial.println(" devices."); // Loop through each device, print out address for(int i=0;i<numberOfDevices; i++){ // Search the wire for address if(sensors.getAddress(tempDeviceAddress, i)){ Serial.print("Found device "); Serial.print(i, DEC); Serial.print(" with address: "); printAddress(tempDeviceAddress); Serial.println(); } else { Serial.print("Found ghost device at "); Serial.print(i, DEC); Serial.print(" but could not detect address. Check power and cabling"); } }}void loop(){ sensors.requestTemperatures(); // Send the command to get temperatures // Loop through each device, print out temperature data for(int i=0;i<numberOfDevices; i++){ // Search the wire for address if(sensors.getAddress(tempDeviceAddress, i)){ // Output the device ID Serial.print("Temperature for device: "); Serial.println(i,DEC); // Print the data float tempC = sensors.getTempC(tempDeviceAddress); Serial.print("Temp C: "); Serial.print(tempC); Serial.print(" Temp F: "); Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit } } delay(5000);}// function to print a device addressvoid printAddress(DeviceAddress deviceAddress) { for (uint8_t i = 0; i < 8; i++){ if (deviceAddress[i] < 16) Serial.print("0"); Serial.print(deviceAddress[i], HEX); }}

View raw code

How the code works

The code uses several useful methods to handle multiple DS18B20 sensors.

You use the getDeviceCount() method to get the number of DS18B20 sensors on the data line.

numberOfDevices = sensors.getDeviceCount();

The getAddress() method finds the sensors addresses:

if(sensors.getAddress(tempDeviceAddress, i)){

The address is unique for each sensor. So each sensor can be identified by its address.

Then, you use the getTempC() method that accepts as argument the device address. With this method, you can get the temperature from a specific sensor:

float tempC = sensors.getTempC(tempDeviceAddress);

To get the temperature in Fahrenheit degrees, you can use the getTemF(). Alternatively, you can convert the temperature in Celsius to Fahrenheit as follows:

DallasTemperature::toFahrenheit(tempC)

Demonstration

After uploading the code, open your Serial Monitor at a baud rate of 115200. You should get all your sensors readings displayed as shown below:

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (13)

Display DS18B20 Temperature Readings in a Web Server

To build the web server we’ll use theESPAsyncWebServer library that provides an easy way to build an asynchronous web server. Building an asynchronous web server has several advantages. We recommend taking a quick look at the library documentation on its GitHub page.

Installing the ESPAsyncWebServer library

The ESPAsyncWebServer library is not available to install in the Arduino IDE Library Manager. So, you need to install it manually.

Follow the next steps to install theESPAsyncWebServerlibrary:

(Video) ESP8266 DHT11/DHT22 Temperature and Humidity Web Server with Arduino IDE - Demo

  1. Click here to downloadthe ESPAsyncWebServer library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should getESPAsyncWebServer-masterfolder
  3. Rename your folder fromESPAsyncWebServer-mastertoESPAsyncWebServer
  4. Move theESPAsyncWebServerfolder to your Arduino IDE installation libraries folder

Installing the ESPAsync TCP Library

TheESPAsyncWebServer library requires the ESPAsyncTCPlibrary to work. Follow the next steps to install that library:

  1. Click here to download the ESPAsyncTCP library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get ESPAsyncTCP-masterfolder
  3. Rename your folder fromESPAsyncTCP-master to ESPAsyncTCP
  4. Move theESPAsyncTCP folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Code (DS18B20 Async Web Server)

Open your Arduino IDE and copy the following code.

/********* Rui Santos Complete project details at https://RandomNerdTutorials.com *********/// Import required libraries#ifdef ESP32 #include <WiFi.h> #include <ESPAsyncWebServer.h>#else #include <Arduino.h> #include <ESP8266WiFi.h> #include <Hash.h> #include <ESPAsyncTCP.h> #include <ESPAsyncWebServer.h>#endif#include <OneWire.h>#include <DallasTemperature.h>// Data wire is connected to GPIO 4#define ONE_WIRE_BUS 4// Setup a oneWire instance to communicate with any OneWire devicesOneWire oneWire(ONE_WIRE_BUS);// Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire);// Variables to store temperature valuesString temperatureF = "";String temperatureC = "";// Timer variablesunsigned long lastTime = 0; unsigned long timerDelay = 30000;// Replace with your network credentialsconst char* ssid = "REPLACE_WITH_YOUR_SSID";const char* password = "REPLACE_WITH_YOUR_PASSWORD";// Create AsyncWebServer object on port 80AsyncWebServer server(80);String readDSTemperatureC() { // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus sensors.requestTemperatures(); float tempC = sensors.getTempCByIndex(0); if(tempC == -127.00) { Serial.println("Failed to read from DS18B20 sensor"); return "--"; } else { Serial.print("Temperature Celsius: "); Serial.println(tempC); } return String(tempC);}String readDSTemperatureF() { // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus sensors.requestTemperatures(); float tempF = sensors.getTempFByIndex(0); if(int(tempF) == -196){ Serial.println("Failed to read from DS18B20 sensor"); return "--"; } else { Serial.print("Temperature Fahrenheit: "); Serial.println(tempF); } return String(tempF);}const char index_html[] PROGMEM = R"rawliteral(<!DOCTYPE HTML><html><head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous"> <style> html { font-family: Arial; display: inline-block; margin: 0px auto; text-align: center; } h2 { font-size: 3.0rem; } p { font-size: 3.0rem; } .units { font-size: 1.2rem; } .ds-labels{ font-size: 1.5rem; vertical-align:middle; padding-bottom: 15px; } </style></head><body> <h2>ESP DS18B20 Server</h2> <p> <i class="fas fa-thermometer-half" style="color:#059e8a;"></i> <span class="ds-labels">Temperature Celsius</span> <span id="temperaturec">%TEMPERATUREC%</span> <sup class="units">&deg;C</sup> </p> <p> <i class="fas fa-thermometer-half" style="color:#059e8a;"></i> <span class="ds-labels">Temperature Fahrenheit</span> <span id="temperaturef">%TEMPERATUREF%</span> <sup class="units">&deg;F</sup> </p></body><script>setInterval(function ( ) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("temperaturec").innerHTML = this.responseText; } }; xhttp.open("GET", "/temperaturec", true); xhttp.send();}, 10000) ;setInterval(function ( ) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("temperaturef").innerHTML = this.responseText; } }; xhttp.open("GET", "/temperaturef", true); xhttp.send();}, 10000) ;</script></html>)rawliteral";// Replaces placeholder with DS18B20 valuesString processor(const String& var){ //Serial.println(var); if(var == "TEMPERATUREC"){ return temperatureC; } else if(var == "TEMPERATUREF"){ return temperatureF; } return String();}void setup(){ // Serial port for debugging purposes Serial.begin(115200); Serial.println(); // Start up the DS18B20 library sensors.begin(); temperatureC = readDSTemperatureC(); temperatureF = readDSTemperatureF(); // Connect to Wi-Fi WiFi.begin(ssid, password); Serial.println("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); // Print ESP Local IP Address Serial.println(WiFi.localIP()); // Route for root / web page server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor); }); server.on("/temperaturec", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", temperatureC.c_str()); }); server.on("/temperaturef", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", temperatureF.c_str()); }); // Start server server.begin();} void loop(){ if ((millis() - lastTime) > timerDelay) { temperatureC = readDSTemperatureC(); temperatureF = readDSTemperatureF(); lastTime = millis(); } }

View raw code

Insert your network credentials in the following variables, and the code will work straight away.

const char* ssid = "REPLACE_WITH_YOUR_SSID";const char* password = "REPLACE_WITH_YOUR_PASSWORD";

How the Code Works

In the following paragraphs we’ll explain how the code works. Keep reading if you want to learn more or jump to the “Demonstration” section to see the final result.

Importing libraries

First, import the required libraries.

#include <Arduino.h>#include <ESP8266WiFi.h>#include <Hash.h>#include <ESPAsyncTCP.h>#include <ESPAsyncWebServer.h>#include <OneWire.h>#include <DallasTemperature.h>

Instantiate DS18B20 Sensor

Define the GPIO that the DS18B20 data pin is connected to. In this case, it’s connected to GPIO 4(D1).

#define ONE_WIRE_BUS 4

Instantiate the instances needed to initialize the sensor:

// Setup a oneWire instance to communicate with any OneWire devicesOneWire oneWire(ONE_WIRE_BUS);// Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire);

Create variables that will hold the temperature and humidity as String values:

String temperatureF = "";String temperatureC = "";

We’ll get new sensor readings every 30 seconds. You can change that in the timerDelay variable.

unsigned long lastTime = 0; unsigned long timerDelay = 30000;

Setting your network credentials

Insert your network credentials in the following variables, so that the ESP8266 can connect to your local network.

const char* ssid = "REPLACE_WITH_YOUR_SSID";const char* password = "REPLACE_WITH_YOUR_PASSWORD";

Create anAsyncWebServer object on port 80.

AsyncWebServer server(80);

Read Temperature Functions

Then, we create two functions to read the temperature.

The readDSTemperatureC() function returns the readings in Celsius degrees.

String readDSTemperatureC() { // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus sensors.requestTemperatures(); float tempC = sensors.getTempCByIndex(0); if(tempC == -127.00){ Serial.println("Failed to read from DS18B20 sensor"); return "--"; } else { Serial.print("Temperature Celsius: "); Serial.println(tempC); } return String(tempC);}

In case the sensor is not able to get a valid reading, it returns -127. So, we have an if statement that returns two dashes (–-) in case the sensor fails to get the readings.

if(tempC == -127.00){ Serial.println("Failed to read from DS18B20 sensor"); return "--";

The reaDSTemperatureF() function works in a similar way but returns the readings in Fahrenheit degrees.

The readings are returned as string type. To convert a float to a string, use the String() function.

return String(tempC);

Building the Web Page

The next step is building the web page. The HTML and CSS needed to build the web page are saved on the index_html variable.

In the HTML text we have TEMPERATUREC and TEMPERATUREF between % signs. This is a placeholder for the temperature values.

This means that this %TEMPERATUREC% text is like a variable that will be replaced by the actual temperature value from the sensor. The placeholders on the HTML text should go between % signs.

We’ve explained in great detail how the HTML and CSS used in this web server works in a previous tutorial. So, if you want to learn more, refer to the next project:

(Video) Build an ESP32 Web Server with Arduino IDE

  • DHT11/DHT22 Temperature and Humidity Web Server with Arduino IDE

Processor

Now, we need to create the processor() function, that will replace the placeholders in our HTML text with the actual temperature values.

// Replaces placeholder with DS18B20 valuesString processor(const String& var){ //Serial.println(var); if(var == "TEMPERATUREC"){ return temperatureC; } else if(var == "TEMPERATUREF"){ return temperatureF; } return String();}

When the web page is requested, we check if the HTML has any placeholders. If it finds the %TEMPERATUREC% placeholder, we return the temperature in Celsius by calling the readDSTemperatureC() function created previously.

if(var == "TEMPERATUREC"){ return temperatureC;}

If the placeholder is %TEMPERATUREF%, we return the temperature in Fahrenheit.

else if(var == "TEMPERATUREF"){ return temperatureF;}

setup()

In the setup(), initialize the Serial Monitor for debugging purposes.

Serial.begin(115200);

Initialize the DS18B20 temperature sensor.

sensors.begin();

Get the current temperature values:

temperatureC = readDSTemperatureC();temperatureF = readDSTemperatureF();

Connect to your local network and print the ESP8266 IP address.

WiFi.begin(ssid, password);Serial.println("Connecting to WiFi");while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(".");}Serial.println(); // Print ESP8266 Local IP AddressSerial.println(WiFi.localIP());

Finally, add the next lines of code to handle the web server.

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor);});server.on("/temperaturec", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", temperatureC.c_str());});server.on("/temperaturef", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", temperatureF.c_str());});

When we make a request on the root URL, we send the HTML text that is stored in the index_html variable. We also need to pass the processor function, that will replace all the placeholders with the right values.

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor);});

We need to add two additional handlers to update the temperature readings. When we receive a request on the/temperaturecURL, we simply need to send the updated temperature value. It is plain text, and it should be sent as a char, so, we use the c_str() method.

server.on("/temperaturec", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", temperatureC.c_str());});

The same process is repeated for the temperature in Fahrenheit.

server.on("/temperaturef", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", temperatureF.c_str());});

Lastly, we can start the server.

server.begin();

In the loop(), update the temperature values every 30 seconds (timerDelay variable).

void loop(){ if ((millis() - lastTime) > timerDelay) { temperatureC = readDSTemperatureC(); temperatureF = readDSTemperatureF(); lastTime = millis(); } }

That’s pretty much how the code works.

Demonstration

After uploading the code, open the Arduino IDE Serial Monitor at a baud rate of 115200.After a few seconds your IP address should show up.

In your local network, open a browser and typethe ESP8266 IP address.

Now youcan seetemperature in Celsius and Fahrenheit in your web server. The sensor readings update automatically without the need to refresh the web page.

ESP8266 DS18B20 Sensor Web Server Arduino IDE (Single, Multiple) | Random Nerd Tutorials (14)

Wrapping Up

This was an in-depth guide on how to use the DS18B20 temperature sensor with the ESP8266 and display the readings on a web server.

The DS18B20 communicates via one-wire protocol and each sensor has a unique 64-bit serial code, which means you can read many sensors on the same data pin.

We hope you’ve found this tutorial useful. We have other tutorials with the ESP8266 that you may also like:

(Video) ESP32: ESP-NOW Web Server Sensor Dashboard (ESP-NOW + Wi-Fi)

  • ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)
  • ESP8266: DHT Temperature and Humidity Readings in OLED Display
  • ESP8266 0.96 inch OLED Display with Arduino IDE
  • ESP8266 DHT11/DHT22 Temperature and Humidity Web Server with Arduino IDE

Learn more about the ESP8266 with Home Automation using ESP8266 (eBook + Video Course).

Thanks for reading.

FAQs

How do I use 2 DS18B20? ›

Wiring Multiple DS18B20 Sensors to Arduino

Connections are pretty straightforward. Begin by connecting all of the DS18B20s in parallel, sharing all of the VDD, GND, and signal pins. Then connect VDD to the Arduino's 5V output, GND to the Arduino's ground, and signal pin to digital pin 2 on the Arduino.

Do you need resistor for DS18B20? ›

Finally, when you're wiring the DS18B20 you need to add a pull-up resistor. Ideally use a 4.7 Ohm resistor (yellow, purple, red) but a 10K (Brown, Black, Orange) will do if that's all you have. This is wired between the digital signal and power pin.

What type of sensor is DS18B20? ›

The core functionality of the DS18B20 is its direct-to- digital temperature sensor. The resolution of the tempera- ture sensor is user-configurable to 9, 10, 11, or 12 bits, corresponding to increments of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C, respectively. The default resolution at power-up is 12-bit.

What is DS18B20 used for? ›

One-wire temperature sensors like the DS18B20 are devices that can measure temperature with a minimal amount of hardware and wiring. These sensors use a digital protocol to send accurate temperature readings directly to your development board without the need of an analog to digital converter or other extra hardware.

How does the DS18B20 work? ›

The DS18B20 is one type of temperature sensor and it supplies 9-bit to 12-bit readings of temperature. These values show the temperature of a particular device. The communication of this sensor can be done through a one-wire bus protocol which uses one data line to communicate with an inner microprocessor.

How does Arduino connect multiple temperature sensors? ›

Multiple DS18B20 temperature sensors with Arduino - YouTube

How do you wire a temp sensor on Arduino? ›

First plug the sensor on the breadboard the connect its pins to the Arduino using the jumpers in the following order: pin 1 to GND; pin 2 to any digital pin (pin 2 in our case); pin 3 to +5V or +3.3V, at the end put the pull-up resistor.

How do you test a DS18B20 sensor? ›

Step 6: DS18B20 - Initial Testing
  1. Usable temperature range: -55 to 125°C (-67°F to +257°F)
  2. 9 to 12 bit selectable resolution.
  3. Uses 1-Wire interface - requires only one digital pin for communication.
  4. Unique 64 bit ID burned into chip.
  5. Multiple sensors can share one pin.
  6. ±0.5°C Accuracy from -10°C to +85°C.

What color is a 4.7 K resistor? ›

A 4.7K Ohm resistor can be identified via resistor color codes of Yellow-Purple-Red-Gold or Yellow-Purple-Black-Brown-Gold.

How do I install OneWire library? ›

Installing Libraries
  1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open. What is this? ...
  2. Type “OneWire” in the search box and install the OneWire library by Paul Stoffregen.
  3. Then, search for “Dallas” and install the Dallas Temperature library by Miles Burton.
2 Jul 2019

How do I connect my digital temperature sensor to my Arduino? ›

First plug the sensor on the breadboard the connect its pins to the Arduino using the jumpers in the following order: pin 1 to GND; pin 2 to any digital pin (pin 2 in our case); pin 3 to +5V or +3.3V, at the end put the pull-up resistor.

How do you test a DS18B20 sensor? ›

Step 6: DS18B20 - Initial Testing
  1. Usable temperature range: -55 to 125°C (-67°F to +257°F)
  2. 9 to 12 bit selectable resolution.
  3. Uses 1-Wire interface - requires only one digital pin for communication.
  4. Unique 64 bit ID burned into chip.
  5. Multiple sensors can share one pin.
  6. ±0.5°C Accuracy from -10°C to +85°C.

How do I connect my DS18B20 to my Raspberry Pi? ›

First, connect the VDD and GND Pins of DS18B20 Sensor to 3.3V and GND Pins of Raspberry Pi. DS18B20 can tolerate +5V Supply. Then connect a 4.7KΩ Resistor between the DQ pin of DS18B20 and 3.3V i.e. a pull-up resistor. Finally, connect the DQ Pin to GPIO4 (i.e. Physical pin 7) of Raspberry Pi.

How do I install OneWire library? ›

Installing Libraries
  1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open. What is this? ...
  2. Type “OneWire” in the search box and install the OneWire library by Paul Stoffregen.
  3. Then, search for “Dallas” and install the Dallas Temperature library by Miles Burton.
2 Jul 2019

Videos

1. ESP32/ESP8266 Plot Sensor Readings in Real Time Charts - Web Server
(Rui Santos)
2. Web Server On ESP-8266
(Volthaus Lab)
3. SD card Webserver using Esp8266 Nodemcu
(Magesh Jayakumar)
4. ESP8266 Web Server (Code and Schematics)
(Rui Santos)
5. ESP32 Email Alert Based on Temperature Threshold (change values on web server)
(Rui Santos)
6. WiFi thermometer with ESP8266
(Ilusys Systems)
Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated: 03/05/2023

Views: 6721

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.