ESP32 with Multiple DS18B20 Temperature Sensors

This guide shows how to read temperature from multiple DS18B20 temperature sensors with the ESP32 using Arduino IDE. We’ll show you how to wire the sensors on the same data bus to the ESP32, install the needed libraries, and a sketch example you can use in your own projects. This tutorial is also compatible with the ESP8266 and the Arduino boards.

If you would like to build a web server displaying readings from multiple sensors, follow the next tutorial: ESP32 Plot Sensor Readings in Charts (Multiple DS18B20 Sensors)

You might also like reading other DS18B20 guides:

Introducing the DS18B20 Temperature Sensor

The DS18B20 temperature sensor is a 1-wire digital temperature sensor. Each sensor has a unique 64-bit serial number, which means you can use many sensors on the same data bus (this means many sensors connected to the same GPIO). This is specially useful for data logging and temperature control projects. The DS18B20 is a great sensor because it is cheap, accurate and very easy to use.

The following figure shows the DS18B20 temperature.

Note: there’s also a waterproof version of the DS18B20 temperature sensor.

Here’s the main specifications of the DS18B20 temperature sensor:

  • Comunicates over 1-wire bus communication
  • Operating range temperature: -55ºC to 125ºC
  • Accuracy +/-0.5 ºC (between the range -10ºC to 85ºC)

From left to right: the first pin is GND, the second is data, and the rightmost pin is VCC.

Where to Buy the DS18B20 Temperature Sensor?

Check the links below to compare the DS18B20 temperature sensor price on different stores:

Wiring Multiple DS18B20 Sensors

Here’s a list of the parts you need to follow this example:

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!

When wiring the DS18B20 temperature sensor you need to add a 4.7k Ohm resistor between VCC and the data line. The following schematic shows an example for three sensors (you can add more sensors if needed).

In the previous schematic, the round side of the sensor is facing backwards. The flat part is facing forward.

Preparing the Arduino IDE

There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language. Follow one of the next tutorials to prepare your Arduino IDE to work with the ESP32, if you haven’t already.

Installing Libraries

Before uploading the code, you need to install two libraries in your Arduino IDE. The OneWire library by Paul Stoffregen and the Dallas Temperature library. Follow the next steps to install those libraries.

OneWire library

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

Dallas Temperature library

  1. Click here to download the DallasTemperature library. You should have a .zip folder in your Downloads
  2. Unzip the .zip folder and you should get Arduino-Temperature-Control-Library-master folder
  3. Rename your folder from Arduino-Temperature-Control-Library-master to DallasTemperature
  4. Move the DallasTemperaturefolder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Getting the DS18B20 Sensor Address

Each DS18B20 temperature sensor has a serial number assigned to it. First, you need to find that number to label each sensor accordingly. You need to do this, so that later you know from which sensor you’re reading the temperature from.

Upload the following code to the ESP32. Make sure you have the right board and COM port selected.

/*
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
 */

#include <OneWire.h>

// Based on the OneWire library example

OneWire ds(4);  //data wire connected to GPIO 4

void setup(void) {
  Serial.begin(115200);
}

void loop(void) {
  byte i;
  byte addr[8];
  
  if (!ds.search(addr)) {
    Serial.println(" No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  Serial.print(" ROM =");
  for (i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }
}

View raw code

Wire just one sensor at a time to find its address (or successively add a new sensor) so that you’re able to identify each one by its address. Then, you can add a physical label to each sensor. Open the Serial Monitor at a baud rate of 9600 and you should get something as follows (but with different addresses):

Untick the “Autoscroll” option so that you’re able to copy the addresses. In our case we’ve got the following addresses:

  • Sensor 1: 28 FF 77 62 40 17 4 31
  • Sensor 2: 28 FF B4 6 33 17 3 4B
  • Sensor 3: 28 FF A0 11 33 17 3 96

Getting Temperature From Multiple Sensors

Getting the temperature from multiple sensors on the same common data bus is very straightforward.

The example code below reads temperature in Celsius and Fahrenheit from each sensor and prints the results in the Serial Monitor.

/*
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
 */

// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is connected to GPIO15
#define ONE_WIRE_BUS 15
// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

DeviceAddress sensor1 = { 0x28, 0xFF, 0x77, 0x62, 0x40, 0x17, 0x4, 0x31 };
DeviceAddress sensor2 = { 0x28, 0xFF, 0xB4, 0x6, 0x33, 0x17, 0x3, 0x4B };
DeviceAddress sensor3= { 0x28, 0xFF, 0xA0, 0x11, 0x33, 0x17, 0x3, 0x96 };

void setup(void){
  Serial.begin(115200);
  sensors.begin();
}

void loop(void){ 
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  
  Serial.print("Sensor 1(*C): ");
  Serial.print(sensors.getTempC(sensor1)); 
  Serial.print(" Sensor 1(*F): ");
  Serial.println(sensors.getTempF(sensor1)); 
 
  Serial.print("Sensor 2(*C): ");
  Serial.print(sensors.getTempC(sensor2)); 
  Serial.print(" Sensor 2(*F): ");
  Serial.println(sensors.getTempF(sensor2)); 
  
  Serial.print("Sensor 3(*C): ");
  Serial.print(sensors.getTempC(sensor3)); 
  Serial.print(" Sensor 3(*F): ");
  Serial.println(sensors.getTempF(sensor3)); 
  
  delay(2000);
}

View raw code

Open the Serial Monitor at a baud rate of 115200 and you should get something similar.

How the Code Works

First, include the needed libraries:

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

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

// Data wire is connected to ESP32 GPIO15
#define ONE_WIRE_BUS 15
// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

Start the Dallas temperature library for the DS18B20 sensor.

sensors.begin();

Then, enter the addresses you’ve found previously for each temperature sensor. In our case, we have the following:

DeviceAddress sensor1 = { 0x28, 0xFF, 0x77, 0x62, 0x40, 0x17, 0x4, 0x31 };
DeviceAddress sensor2 = { 0x28, 0xFF, 0xB4, 0x6, 0x33, 0x17, 0x3, 0x4B };
DeviceAddress sensor3= { 0x28, 0xFF, 0xA0, 0x11, 0x33, 0x17, 0x3, 0x96 };

In the setup(), initialize a Serial communication and start the Dallas temperature library for the DS18B20 sensor.

void setup(void){
  Serial.begin(115200);
  sensors.begin();
}

In the loop(), request the temperatures both in Celsius and Fahrenheit and print the results on the Serial Monitor.

First, you need to request the temperatures using the following line of code:

sensors.requestTemperatures(); // Send the command to get temperatures

Then, you can request the temperature by using the sensors address:

  • sensors.getTempC(SENSOR_ADDRESS) – requests the temperature in Celsius
  • sensors.getTempF(SENSOR_ADDRESS) – requests the temperature in Fahrenheit

For example, to request temperature in Celsius for sensor 1, you use:

sensors.getTempC(sensor1)

In which sensor1 is a variable that holds the address of the first sensor.

This is just a simple sketch example to show you how to get temperature from multiple DS18B20 sensors using the ESP32. This code is also compatible with the ESP8266 and Arduino boards.

Taking It Further

Getting temperature from multiple DS18B20 temperature sensors is specially useful in monitoring and temperature control projects and data logging. Learn how to log the collected data to a microSD card:

You can also publish your readings via MQTT to Node-RED and display your data in charts. We have a tutorial about that subject in the link below:

We hope you’ve found this tutorial useful. If you like ESP32 and you want to learn more, we recommend enrolling in Learn ESP32 with Arduino IDE course.

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

80 thoughts on “ESP32 with Multiple DS18B20 Temperature Sensors”

  1. Rui,this can better,see examples DallasTemperature sketch Multiple,there is no need to look for the adresses of the sensors.

    Reply
    • Yes. You are right, you can use that sketch to automatically get the temperature from all the devices.
      But if you have a lot of devices it can be difficult to know which temperature reading corresponds to which sensor.
      Thank you for you comment.
      Regards,
      Sara 🙂

      Reply
  2. Rui,
    Excellent project, very useful for home automation projects, the only is missing is to add a very cheap transmitter (maybe in 445MHz band) to connect remote sensors if that may be possible. The biggest problem is that the sensors location are different locations and to use one wire to connect the sensors is not always convenient. maybe next project will tackle that IoT home application

    Reply
    • Hi Ion.
      We don’t have any tutorial like that at the moment.
      As a suggestion, you can use several ESP8266 or ESP32 (each one with different DS18B20 temperature sensors) to send the sensors readings to Node-RED using MQTT. To help you do this, you can take a look at the following tutorial:
      What is MQTT and How it Works?
      (This only works if you have Wi-Fi coverage)
      I hope this helps.
      Thank you for your comment,
      Regards,
      Sara

      Reply
  3. Great tutorial. I am looking to monitor multiple freezers and this should work well. However, how long can I cable the temp sensors from the ESP? Could I do the same with an Arduino? Also what would be the best way to send an alert if the temp rises above a preset temp?

    Reply
  4. Hi Rui Santos,
    many, many thanks for your excellent tutorials. These are the best one can find in the internet !! and they solved many problems I had bofore reading !!
    Greetings and thanks also to Sara Santos,
    W. Reitmayr

    Reply
  5. Thank you for this nice tutorial. I am right now working on a project with several sensors and some questions came up that was all addressed here! Great timing 😉
    I have a question regarding IO pins, is it possible to use any GPIO pin for the 1w sensor? I have an ESP-07 (generic) and I got it to work with GPIO 12 and 15 but not with 4 or 5 .

    Reply
    • Yes, you are right. Thank you for the suggestion!
      Also, thank you for mentioning our tutorials in your website.
      Regards,
      Sara 🙂

      Reply
  6. What is maximum (data) cable length for this sensors?
    I wanted to put one sensor outside and one indoor so if outside temp is lower, servo will open one window lever and fan will blow fresh air in.

    Reply
  7. Hi Rui/Sara, thanks for the explanation. Is it true that you won’t have to connect the Vcc pin ?
    As far as I understand the specs it seems that the sensor would pick the needed power from the dataline (it is called parasite power).
    Second question: is the sensor used with the (default) highest resolution ? I tested the program and I got very precisely 2 decimals in the displayed result.

    Reply
    • Hi Hans.
      Yes, you can use the sensor in parasite mode. It get derives the power from the dataline.
      You can set the sensor resolution in the code, by using: sensors.setResolution(SENSOR, RESOLUTION)
      Accordingly to the datasheet, it provides a maximum of 12-bit resolution: datasheets.maximintegrated.com/en/ds/DS18B20.pdf
      Regards,
      Sara 🙂

      Reply
  8. Excelente tutorial, quisiera saber si este mismo metodo me serviria para otros sensores como de humedad o efecto hall, o son exclusivos del sensor de temperatura

    Reply
  9. Hi,

    When i put this project together it would not give me anything at all.
    I spent hours and hours checking my wiring, re-checking the code, reloading my ESP32 drivers etc.

    In the end i found it was the Baud Rate of the Serial Monitor.
    You said:
    “Open the Serial Monitor at a baud rate of 115200 and…”
    but when i changed the Baud Rate to 9600 baud, it all started to work.

    In your code you have a line which says “Serial.begin(9600)”.
    Doesn’t this suggest that the Serial Monitor should be set to 9600 not 115200 as the text says?

    When i changed your code in the sketch to say “Serial.begin(115200)”
    I found that the Serial Monitor window only showed output when it was set to 115200.

    I am only a beginner, but i would say that the two things are definitely connected?

    Frustrated
    Chris

    Reply
    • Hi Chris.
      I’m so sorry for that trouble.
      It was my fault while writing the post.
      When you set the Serial.begin(9600) in the code, you need to open the serial monitor at 9600 baud rate.
      When you set Serial.being(115200) in the code, you need to open the serial monitor at a baud rate of 115200.
      The first code is set to 9600 because we’re using an example from the OneWire library, but you can set other baud rate in the code.
      The second code uses 115200.
      I’m so sorry for the typo. It is fixed now.
      Regards,
      Sara

      Reply
    • Hi Roberto.
      It depends on the communication protocol of the sensor.
      I don’t think you can implement this configuration with that one.
      What’s the communication protocol supported by the sensor?
      Regards,
      Sara

      Reply
  10. Can this setup be used to activate a relay to turn on a cooling fan? If so, what is the code to be added to make this happen?

    Reply
      • Thank you for sending me this project link. I am concerned about the voltage. It appears to connect the ESP32 to 3.3V. ON the breadboard the LED and the temperature sensor is connected to the same 3.3V. Is this enough voltage to trigger the LED? I am connecting a 12V fan and using a relay to trigger the fan which is why I am asking.

        Also,just a note for your readers. Buy a quality project board. The one I bough does not have pin numbers on the board and the sketch sheet with the board is all out of line and I don’t think the pins are the same as this drawing. I have purchased one that is identical to the pictures in the project sketch.

        Reply
  11. hi. like im not a programer i just copypaste.
    i
    m havingproblems with this code, i dont know if i he to change somethig, it work, but only can read one sensor.
    i cant read the adress of each sensor like it says in the begining using that part of code, can you help, please, thanks a lot

    Reply
  12. Hi
    Can this be made using an ESP32-CAM? I need to use this module for a project but I also need to read the temperature of the room where I take the pic.
    Thanks!

    Reply
  13. Thanks for the greet article.

    I tried it with my Firebeetle ESP32 and 2xDS18B20 (each 3m cable), but the code does not detecting the sensors.
    If i remove one DS18B20 Data-Connector it will receive the Hardware-Adress and an Temperaturevalue. If I remove the other Sensor, I will see the other Adress and Value.
    Is there anything special in my configuration? Maybe an Issue with the Firebeetle or the 3m cables?

    Thanks for help.
    Best regards Tobias

    Reply
  14. Any experience on the maximum length that the cables should have? I would like to use twice DS18B20 in same floor, and I do not know if I can use one D1 mini attached to the both sensors or should I use one ESP to each sensor near to them. So far I got the two sensors running fine in the workbench, but I would like to save time to pass the cables.
    Thanks in advance for your tip.

    Reply
    • I have around 5m to my solar water collectors. I had difficulties with reliability, even with original Dallas or Maxim sensors and UTP cat 5e cable. After +-3 days it started to fail. Firstly I solved it with internet mains socket switch and switching ESP32 off for night. Then it was okay.

      Now I read, that it may fail, when you read multiple sensors at a time. This I read one sensor, wait 100ms and then read the second. Now it works a week with no outage. Maybe this will help you.

      Reply
      • And please note, that Aliexpress clones of DS18B20 worked worse, than originals, outages of data from sensors were more frequent.

        Reply
  15. Hi Guys,
    I am coming back to this project after a long break, but i have some questions:

    Q1: What is the maximum number of DS18B20 sensors that you can attach to one ESP32 board?
    Q2: Does the accuracy of the sensors reduce the more that you put on one string?
    Q3: Is it necessary to vary the pull-up resistor value if you increase the number of sensors on one pin and is there some sort of calculation?
    Q4: Is it possible to increase the number of sensors by using more than one GPIO?
    Q5: If you have 5 sensors, all on one wire, with a meter of cable between each sensor, would this affect the accuracy of the sensor at the end of the wire (5 meters) ?

    Reply
    • Hi Chris.
      I don’t know the answer to all your questions.
      Q3: You can use the same resistor.
      Q4: Yes, you can use more than one GPIO.
      Q5: I think very long cables can interfere with the quality of the reading, but I haven’t experimented it.
      So, I suggest that you take a look at the sensor’s datasheet that might provide more details: https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
      Regards,
      Sara

      Reply
    • A1: In real life, memory of your microcontroller is the limiting factor for how many DS18B20 you can have connected.

      A2: the number of sensors on your OW-bus does not affect measurement accuracy.

      A3: the recommended value is 4k7, but many has found that might be too high, even if you only have one device connected.
      The fail-safe value is often described as 2k2, which is good for dozens of devices.

      A4: yes, you can have several OW-nets connected to different GPIO:s.
      I have used that on a mBed board where I had 4 nets connected to 4 I/O.

      A5: no. The DS18B20 is a digital sensor, meaning that if voltage supply is sufficient and the cabling is good, you will get correct readings. Cable length does not impact accuracy.

      Note: power requirements for this device are modest but not negligible.
      When supply is out of spec, you generally read 85C as the output.
      When this happened to me I added a 100nF cap over gnd and Vcc which cured it.

      Note 2: if you take reading every 5s or even faster, the device will self heat and give a reading higher than expected.

      Note 3: the official programming examples (maximintegrated.com/en/design/technical-documents/app-notes/1/162.html) are riddled with errors. I wrote to Maxim/Dallas probably ten years ago, but the same errors are present to this day.

      Reply
  16. Thanks for the prompt reply Sara,
    I shall do some experiments.

    Thanks for all your hard work on your projects. You really document them well.

    Regards
    Chris

    Reply
  17. Great tutorial!
    Can I receive real-time temperature data on the panel, for example LCD 2004 4×20 HD44780, as well as in a web browser or other android application. What code do I need to apply?
    Regards Przemo!

    Reply
  18. Hello
    I had a problem this week with the ds18b20 sensor using ESP32 and WiFi simultaneously. After many tests (and google) I solved the problem by replacing the official ‘onewire’ library with this one: https://github.com/stickbreaker/OneWire (a forq of the original intended for ESP32).
    I leave this tip here because I know that your website has been an excellent reference for those seeking knowledge. A Brazilian hug from the other side of the ocean for you!

    Reply
  19. Hello,
    Thanks for all your information, your site is great giving detailed description for project building!
    However, I have run into some problems with the use of esp32 and ds18B20, as I can’t get readings out of the sensors.
    The esp32 is a DOIT ESP32 devkit v1 and the sensors are the standard type through the hole and/or the ones that have 1, 1.5 meter cable and are watertight.
    I suspect that it is library issue with the esp32 as the same libs work fine with arduino uno, mini etc. Cable connections have been checked many times. I used the ones suggested in randomnerdtutorials with no luck.
    Could you please point out to me the latest working libraries? Thank you a lot!

    Reply
  20. Hi Sara,
    thanks for this very informative project. I have learned a lot. However, since I am new to Arduino/ESP32 projects, I don’t know all the functions used in the project. Could you kindly tell me as to what is the difference between function calls:
    “sensors.requestTemperature();
    and
    “sensors.getTempC(SENSOR_ADDRESS);
    please?
    And further, where from can get more information on these and/or such functions?
    Thanks for your help in advance.

    Reply
  21. Hi Sara,
    further to my last feedback and question, could you kindly inform where can one find some documetation on “DallasTemperature.h” functions please?

    Thanks for you help in advance.
    Best regards

    Reply
      • Hi Sara,
        Does C++ implementation in ESP32 and/or Arduino IDE offer a single-step program execution option for the purpose of debugging?

        Is there any other program debugging possibility apart from adding some “Serial.print” commands in the prgramm, compiling, downloading and running it – only to find that the effort was in vain?

        I am willing to invest in an hardware addon should there be one available. But unfortunately I am not aware of any such hardware debugging aid. If you happen to know of one, please advise.
        Thanks and best regards

        Reply
  22. Hi out there, hello Sara
    I thought I had added a post to this but it seems not to have vanished unpostet.
    Nevertheless:
    I chained 10 DS18B20 on the OW-Bus to measure the distribution of the temperature on an 3D Printer Bed.
    I found out that the whole chain is 6° off (54°C +- 1°) when the bed has 60°C+-1°
    The data sheet says +- 0.5° accuracy up to +85°C
    Any idea what might be wrong?

    At room temp the readings are comparable to another room thermometer within 1°C
    1° accuracy is good enough all in all, but 6° off for each and every sensor on the chain is weird.
    I set the sample rate to 20sec, so there is enough time for conversion, reading all 10 sensors

    BTW: SD Card issues
    I had bought micro SD cards from AZ Delivery, and none works. Actually they work spurious, when I add some capacitance by putting my finger to the contacts.
    (I will try to add some small capacitors to the MISO and MOSI pins)
    I built a connector interface, to connect the reader card directly to the ESP32, to no avail.
    I bought some other Chinese SD card reader (and have to use an SD to micro SD card adapter.) which works totally fine, even when connected via bread board and jumpers.
    (I assumed that the micro SD card reader has problems due to parasite capacitance. Again not even the shortest connection got them working.)
    I found out that MOSI carries a signal when addressing the SD card reader, but there is no answer on the MISO pin and I could not determine why so.

    So IF problems arise with mounting the SD card, try another reader card.

    Reply
    • Hi.
      Thank you for your input.
      I thought I already answered a similar question you made…
      6ºC accuracy is not good at all. I think it may be because the sensors are of dubious quality and clearly don’t behave as advertised on the datasheet.
      I haven’t tried those sensors with such temperatures, so I don’t have means of comparison…

      AS for the microSD card reader, I use these without problems.

      Reply
  23. I have just started embarking on a project to measure temperature and humidity using DHT-22 sensors and an ESP8266. I ended up on your site because I was looking for how to display the sensor values on an LCD. After reading 2 different tutorials I was impressed by the quality of your writing. Having learned entirely from blog posts, and forum posts I have a high appreciation for quality technical writing. I saw a previous comment where you did say you don’t have a tutorial on how to combine a website based logging with a LCD based display but the writing on both of these articles was so clear I have high hopes of being able to combine both into a final product. All of this to say, thank you for what you’re doing I appreciate it and I wanted you to know that I, at least, think you make a quality product.

    Reply
  24. Olá, queria adicionar vários sensores ds18b20, em pinos diferentes tipo dois em cada, tem algum exemplo nesse tipo?, estou tentando fazer isso, mas sempre é lido o pino(GPIO) declarado primeiro.

    Reply
    • Olá.
      Para isso tem criar differentes instâncias do sensor. Uma para cada pino.
      Por exemplo, para o pino 4 criamos a instancia chamada ds:
      OneWire ds(4); //data wire connected to GPIO 4
      Se quisermos outro pino, por exemplo, GPIO2, temos de criar outra instancia, mas com um nome diferente. Por exemplo:
      OneWire ds1(2);
      Depois tem de fazer tudo igual, mas para as duas intancias.
      Espero ter ajudado.
      Cumprimentos.
      Sara Santos

      Reply
  25. Hi,
    I search a way to store sensor address in EEPROM. Need this for exactly identify a sensor to store data in a DB. I store data order by sensor_name.

    Any good ideas!

    JoVo

    Reply
    • reading and store the sensors is not the problem. Problem is if I change a sensor(damage) the sort order change. So I didn’t know where the sensor (there a 12) was.
      i store sensor data in that way Sensor_1 –> DataDB

      Sensor_1 = 00:00:00:00:00

      so I know every time who is who.

      Reply
  26. Hi,
    I am looking for a solution to monitor / log temperature data of all the cooling devices in my departmental store / supermarket which has about 30 fridges & freezers distributed in ~150 sqmtr area. I want to use One wire sensors (DS18B20) network of clusters, i.e. max 4 to 5 sensors in a cluster physicall connected with an ESP board, and about 5 different clusters (ESP Boards) further connected wireless (either using Wifi or ESP NOW) with the ESP or Arduino Board (could be ESP32, NodeMCU or Arduino UNO).. Hence want to keep a log of all the temperature sensors in an excel file as well as able to monitor the temperature on web server!

    can you pls help me with this project as need some adv on how to design this solution!

    thanks

    Reply
  27. There is a down side to having multiple DS18B20s on one line. First, you don’t know which sensor is which when the app prints out the temperature. Second, when a sensor fails, the new sensor can be in any order in the detection, so if your system depends on knowing the location of the reported data, the Dallas() function isn’t helpful until you physically nail down the locations. Third, the Dallas() function takes time to detect each sensor, and then adds an addition 850 ms minimum for each sensor’s conversion time. You can speed things up by starting the conversion, then go do something for 850+ ms, then come back and read the data and start another conversion. The following code is very fast, where X is the GPIO pin (or pins):

    // — Dallas reader ————————————–
    int dallas(int x) {
    OneWire ds(x) ;
    byte data0 ;
    byte data1 ;
    long result ;

    ds.reset() ;
    ds.write(0xCC) ; // skip command
    ds.write(0xBE) ; // Read first 2 bytes of Scratchpad
    data0 = ds.read() ;
    data1 = ds.read() ;
    result = (data1 << 8) | data0 ;
    // round up (add 1/2 bit) and convert to degrees F times 100
    result = (((result * 90) + 0x04) >> 3 ) + 3200 ; // F x 100
    ds.reset() ;
    ds.write(0xCC) ; // skip command
    ds.write(0x44,1) ; // start conversion
    return result ;

    }
    // —————– end of readtemps() ——————-

    Reply

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.