ESP8266 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server)

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 with DS18B20 Temperature Sensor using Arduino IDE

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:

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

Introducing DS18B20 Temperature Sensor

The DS18B20 temperature sensor is 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.

DS18B20 Temperature Sensor Pinout Pins

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 in waterproof version.

DS18B20 Temperature Sensor Waterproof version

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 the DS18B20 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 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

DS18B20 Temperature Sensor with ESP8266 Parasite Mode Wiring Schematic Diagram

Normal Mode

DS18B20 Temperature Sensor with ESP8266 Normal Mode Wiring Schematic Diagram

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

Read our ESP8266 GPIO Reference Guide to learn more about the ESP8266 GPIOs.

Note: if you’re using an ESP-01, GPIO 2 is 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:

Installing Libraries for DS18B20

To interface with the DS18B20 temperature sensor, you need to install the One Wire library by Paul Stoffregen and the Dallas Temperature library. Follow the next steps to install those libraries.

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

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

Install OneWire library by Paul Stoffregen in Arduino IDE

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

Install DallasTemperature library by Miles Burton in Arduino IDE

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 to
const int oneWireBus = 4;     

// Setup a oneWire instance to communicate with any OneWire devices
OneWire 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.

DS18B20 Single OneWire Temperature Sensor with ESP32 and Arduino IDE on Breadboard

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 to
const int oneWireBus = 4;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire 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.

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 Monitor at a 9600 baud rate. You should get the temperature displayed in both Celsius and Fahrenheit:

DS18B20 Temperature Readings Arduino IDE Serial Monitor

Getting Temperature from Multiple DS18B20 Temperature Sensors

DS18B20 Multiple Temperature Sensors OneWire with ESP32 and Arduino IDE

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:

DS18B20 Multiple Temperature Sensors with ESP32 Wiring Schematic Diagram

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 found
int numberOfDevices;

// We'll use this variable to store a found device address
DeviceAddress 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 address
void 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 Multiple DS18B20 Temperature Sensors Serial Monitor Print readings

Display DS18B20 Temperature Readings in a Web Server

To build the web server we’ll use the ESPAsyncWebServer 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 the ESPAsyncWebServer library:

  1. Click here to download the ESPAsyncWebServer library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get ESPAsyncWebServer-master folder
  3. Rename your folder from ESPAsyncWebServer-master to ESPAsyncWebServer
  4. Move the ESPAsyncWebServer folder to your Arduino IDE installation libraries folder

Installing the ESPAsync TCP Library

The ESPAsyncWebServer library requires the ESPAsyncTCP library 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-master folder
  3. Rename your folder from ESPAsyncTCP-master to ESPAsyncTCP
  4. Move the ESPAsyncTCP 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 devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Create AsyncWebServer object on port 80
AsyncWebServer 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 DHT values
String processor(const String& var){
  //Serial.println(var);
  if(var == "TEMPERATUREC"){
    return readDSTemperatureC();
  }
  else if(var == "TEMPERATUREF"){
    return readDSTemperatureF();
  }
  return String();
}

void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);
  Serial.println();
  
  // Start up the DS18B20 library
  sensors.begin();
  
  // 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", readDSTemperatureC().c_str());
  });
  server.on("/temperaturef", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readDSTemperatureF().c_str());
  });
  // Start server
  server.begin();
}
 
void loop(){
  
}

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 devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

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 an AsyncWebServer 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:

Processor

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

String processor(const String& var){
  //Serial.println(var);
  if(var == "TEMPERATUREC"){
    return readDSTemperatureC();
  }
  else if(var == "TEMPERATUREF"){
    return readDSTemperatureF();
  }
  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 readDSTemperatureC();
}

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

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

setup()

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

Serial.begin(115200);

Initialize the DS18B20 temperature sensor.

sensors.begin();

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 Address
Serial.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", readDSTemperatureC().c_str());
});
server.on("/temperaturef", HTTP_GET, [](AsyncWebServerRequest *request){
  request->send_P(200, "text/plain", readDSTemperatureF().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 /temperaturec URL, 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", readDSTemperatureC().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", readDSTemperatureF().c_str());
});

Lastly, we can start the server.

server.begin();

Because this is an asynchronous web server, we don’t need to write anything in the loop().

void loop(){
  
}

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 type the ESP8266 IP address.

Now you can see temperature in Celsius and Fahrenheit in your web server. The sensor readings update automatically without the need to refresh the web page.

ESP8266 Web Server with DS18B20 OneWire Temperature Sensor Arduino IDE

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:

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

Thanks for reading.


Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

91 thoughts on “ESP8266 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server)”

  1. Cool item, like to see more of this 🙂 and if I may,… some more articles with ESP modules in low power/power save mode (where the whole solution is powered by 1 18650 battery…

  2. Hi, thanks for the neat project, it looks very useful, and I may well build one of these for outdoor temp while we are living in our motor home this winter. Question though, could one add another sensor of the same kind for outdoor and use one for indoor?? Thus two Dallas temp sensors? Also could one also add a LCD display to display the temps locally as well as on the network?

  3. Hi, if I try to compile this code on my IDE I get this error:

    Temperature_Sensor:17: error: ‘D1’ was not declared in this scope

    #define ONE_WIRE_BUS D1

    It seems that D1 is not recognize. What do you think about?

  4. Hi. Great tutorial as usual. I have a suggestion for another ESP tutorial and that is to be able to pass data to a MySQL db. I have one set up on one of my RasPi’s and it receives data from my other RasPis but I also have ESP modules that I would like to collect data from but can’t figure out how to do that. I think this would be a great general interest topic to cover…if it can be done. 🙂
    Thanks,
    Bruce

  5. Hi Rui,

    I want to try this with ESP8266-01, GPIO2, so what should I use instead of “D1” ?

    Thanks in advance

  6. Hoi Rui

    Would you please explain to me what to change in the sketch so that the web-page is refreshing every x seconds ?

    regards Ton.

  7. Another great tutorial Rui, Thanks! I usually use an ESP07 or ESP12 in projects. Can you tell me how the GPIO numbers relate to the “Dn” numbering of the Nodemcu 1.0 Module. Thanks.

  8. Hello Rui, I built your project with the esp and DS1820B and it works fine with my mobile device but when I use Chrome or Firefox I don’t get a response. The ESP sees the connect but the browser just sits there. Any ideas?

  9. Yes !!!…as always…good job!!!!
    I am waiting for a light in the path from you to write a tutorial about FTP and this ESP8266 Node MCU, if you have time, one day maybe?

  10. bonsoir
    j’ai lu avec attention votre tuto
    peut on le mettre en place avec un réseau adhoc
    cordialement
    pierre

  11. Realy nice and informative thank you somuch for your kindness to freely over flow the knowldge. It is help to poors who cannot spend money for learning. God will take care of you. Thanks for shearing.

  12. I have just created an account for your home automation server and have set up a led and its working perfectly – Thank you.

    I also wanted to monitor room temperature, but cant see how to do this on the home automation server – is this possible?

  13. Great tutorial !!
    Btw, I have a question, how can I update the temparature data, when it changes, to the webserver without reloading the page ??
    Thank you for reading !

    • You can either assign a fixed IP address in your router to your ESP’s MAC address.
      Or simply Google ESP8266 Arduino IDE fixed IP address and you’ll find a snippet of code that you can use

  14. Many thanks for posting the article and code. Works like a charm on my basic ESP2866 and the DS18B20 board that I had from a Pi project. My first couple of days with the ESP8266, what an amazing piece of kit!

  15. Hi Rui, Merry Christmas.

    First of all, thanks for another great tutorial.

    I built the project with the esp and DS1820B and it works fine.

    Now I’m building another project, reads the data with ESP, and displays in serial terminal, showing like in the browser, but I see trash.
    How do I translate the view, it would be like in the browser?
    And how I present data also in LCD?
    Can you give me some aimed please?

    Thanks a lot.

  16. Hi Rui, Thank you for your comment.
    The Baud rate is OK.
    I see that the results of the measurement, but it probably displays HTML with a lot of other data.
    I would like to isolate the data of temperature, how do I do it?

    Thanks.

  17. Hello Rui
    i use fdti, esp8266-01, ds18b20
    I modified the line
    #define ONE_WIRE_BUS 5
    to
    #define ONE_WIRE_BUS 2 (gpio2)
    It worked once until “New client”
    Without being able to access the web
    Since the script stops after the ip address
    why ?
    Best regards
    Pierre

  18. As I am typing this reply the browser is still trying to connect to the ESP-12. It’s now more then 5 minutes. The serial monitor gives an IP and as soon as I type in the IP it shows: New client but nothing happens. As a matter of fact, It is (the browser) still trying to connect.

    • It looks like you’re not entering the right IP address in your web browser or your ESP is not establishing a Wi-Fi connection with your router.
      Make sure you double-check the serial monitor and it prints the IP address that you’re using to access in your web browser.

      • Dear Rui,
        ESP is connected to wifi, I know IP address but WWW page isn’t available, also serial moitor shows nothing. Any ideas what could be the problem ?

        Thx
        Marcin

  19. @marc and @marcin

    Try using an other pin for the ds18B20 sensor. I had to connect to D5 instead of D1. The page loaded instantly when connected to the right port.

  20. Hello!

    I’ve did this project but now i want to learn something new. For example i want to add an LED which indicates readings from ds18b20, how to do that?

    Regards,
    Hrvoje

  21. Hi,
    Thank you for your tutorial.
    Will the same code work in all the development board for ESP8266?
    If not what changes do we need to make?

    Thanking you in advance.
    GK

    • Hi.
      This code works for ESP8266.
      It should work in all models.
      The only thing you may need to change is the pin that the sensor is connected to.
      In our example it is connected to D1(GPIO 5). You may need to connect to another pin, in case your specific development board doesn’t have that pin available.
      I hope this answers your question.
      Regards,
      Sara

  22. Hi and thanks a lot for your toutorials, I’m trying to get connected with web server, I’m using an ESP01, and there is no way to do it.
    I found now in my nettwork list “ESP_89ED249” network, I’m connected to this and by ipconfig I know the IP address (192.168.4.1), if I type this on my Chrome I’m able to see the web server…
    Please tell me what is going wrong.
    Another issue I’m don’t able to get data from DHT11 sensor, any suggestion for this?

  23. Thanks for your tutorials and cord work, these days i,m work on another job. After that I’l go throw and inform you.

  24. Hi,
    Thank you very much for your tutorials.
    One question: is it possible to use second ESP8266 (with LCD for example) in this system to display measured temperature on LCD? I’d like to measure water temperature in a pool and display the result on both side: on PC and LCD. Thank you for your answer.
    Darko

  25. My ESP 8266 would only connect to my wifi if I added delay(10); after
    Serial.begin(115200);
    Not to sure why but works perfectly now.
    Thanks for code. Also, enjoying your ESP 32 book

    • Thank you for sharing that. It may be useful for our readers.
      I’m glad you’re enjoying our ESP32 course.
      Regards,
      Sara

  26. hey, thanks for the tutorial, but i want to ask about the use of ds18b20 with esp board, i heard that digital pin of esp has input range 0 to 3,3 and analog pin 0 to 1. So does it save using a ds18b20 modul for esp ?
    thanks in advance

  27. Hi Sara/Rui,
    I have an Arduino Mega running an established Aquaponics garden. What project do you offer that I can purchase to make the senors visible online, not just on my local network?

  28. I am using the same sketch with addition to displaying the values on an OLED screen, but the values are getting distorted on the display as soon as i connect more than one sensor, could someone help me with this i am using OLED in I2C interface.

    • Hi.
      With those details, it is very difficult to find out what can be wrong.
      You can read our OLED guide with the ESP8266 and see if it helps find out what might be wrong.
      Regards,
      Sara

Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.