ESP32 DS18B20 Temperature Sensor With Arduino IDE (Single, Multiple, Web Server) - Random Nerd Tutorials
ESP32 DS18B20 Temperature Sensor With Arduino IDE (Single, Multiple, Web Server) - Random Nerd Tutorials
Menu
This is a in-depth guide for the DS18B20 temperature sensor with ESP32 using
Arduino IDE. We’ll show you 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.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 1/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
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.
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.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 2/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Parts Required
To follow this tutorial you need the following parts:
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 3/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Schematic – ESP32
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 chose either modes.
Parasite Mode
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 4/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Normal Mode
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 5/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Installing Libraries
To interface with the DS18B20 temperature sensor, you need to install the One
Wire library by Paul Sto regen and the Dallas Temperature library. Follow the
next steps to install those libraries.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 6/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
2. Type “onewire” in the search box and install OneWire library by Paul
Sto regen.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 7/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
/*********
Rui Santos
Complete project details at https://RandomNerdTutorials.com
*********/
#include <OneWire.h>
#include <DallasTemperature.h>
void setup() {
// Start the Serial Monitor
Serial.begin(115200);
// Start the DS18B20 sensor
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
fl d ( )
View raw code
There are many di erent 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.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs2t… 9/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
#include <OneWire.h>
#include <DallasTemperature.h>
Create the instances needed for the temperature sensor. The temperature
sensor is connected to GPIO 4 .
Serial.begin(115200);
sensors.begin();
sensors.requestTemperatures();
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 10/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Serial.print(temperatureC);
Serial.println("ºC");
Serial.print(temperatureF);
Serial.println("ºF");
delay(5000);
Demonstration
After uploading the code, you should get your sensor readings displayed in the
Serial Monitor:
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 11/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 12/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 13/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
/*********
Rui Santos
Complete project details at https://RandomNerdTutorials.com
*********/
#include <OneWire.h>
#include <DallasTemperature.h>
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 14/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
// Setup a oneWire instance to communicate with any OneWire devices (not just
OneWire oneWire(ONE_WIRE_BUS);
void setup(){
// start serial port
Serial.begin(115200);
Demonstration
In this example, we’re using three DS18B20 temperature sensors. This is what we
get on the Arduino IDE Serial Monitor.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 15/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 16/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 17/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
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.
1. Click here to download the AsyncTCP library. You should have a .zip folder
in your Downloads folder
2. Unzip the .zip folder and you should get AsyncTCP-master folder
3. Rename your folder from AsyncTCP-master to AsyncTCP
4. Move the AsyncTCP folder to your Arduino IDE installation libraries folder
5. Finally, re-open your Arduino IDE
/*********
Rui Santos
Complete project details at https://RandomNerdTutorials.com
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 18/50
22/3/2021
p p ESP32
j DS18B20 Temperature Sensor
p with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
*********/
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#endif
#include <OneWire.h>
#include <DallasTemperature.h>
Insert your network credentials in the following variables and the code will work
straight away.
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 nal
result.
Importing libraries
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <OneWire.h>
#include <DallasTemperature.h>
De ne the GPIO that the DS18B20 data pin is connected to. In this case, it’s
connected to GPIO 4 .
#define ONE_WIRE_BUS 4
Insert your network credentials in the following variables, so that the ESP8266
can connect to your local network.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 20/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
AsyncWebServer server(80);
String readDSTemperatureC() {
// Call sensors.requestTemperatures() to issue a global temperature and Request
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.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 21/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
if(tempC == -127.00){
Serial.println("Failed to read from DS18B20 sensor");
return "--";
The readings are returned as string type. To convert a oat to a string, use the
String() function.
return String(tempC);
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.
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.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 22/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
When the web page is requested, we check if the HTML has any placeholders. If it
nds the %TEMPERATUREC% placeholder, we return the temperature in Celsius by
calling the readDSTemperatureC() function created previously.
if(var == "TEMPERATUREC"){
return readDSTemperatureC();
}
setup()
Serial.begin(115200);
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 23/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
sensors.begin();
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Finally, add the next lines of code to handle the web server.
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.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 24/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
server.begin();
void loop(){
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 25/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Demonstration
After uploading the code, open the Arduino IDE Serial Monitor at a baud rate of
115200. Press the ESP32 on-board RST button and after a few seconds your IP
address should show up.
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.
Wrapping Up
We hope you’ve found this tutorial useful. We have guides for other sensors and
modules with the ESP32 that you may like:
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 26/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
If you want to learn more about the ESP32 take a look at our course, or check or
ESP32 free resources:
Build Web Server projects with the ESP32 and ESP8266 boards to control outputs
and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server
communication protocols DOWNLOAD »
Recommended Resources
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 27/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Home Automation using ESP8266 eBook and video course » Build IoT and
home automation projects.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 28/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 29/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 30/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 31/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
SUBSCRIBE
Kelvin
July 15, 2019 at 8:26 pm
Make sense!
Reply
Trull
September 2, 2019 at 7:14 am
The above code works really well on my Heltec Lora ESP32 board at
240MHz, but the onewire library breaks down if you reduce the speed of
the processor to save energy or for compatibility with other interfaces.
Current thinking seems to be this is because the onewire interface is
bitbashed and processor interrupts smooth operation.
Reply
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 32/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Peter Laneville
October 28, 2019 at 2:01 pm
When I add a second sensor as depicted and run the multiple sensor
code it can’t nd any sensors (“Location devices…Found 0devices”).
Reply
Sara Santos
October 29, 2019 at 11:14 am
Hi Peter.
I don’t know what can be the problem.
Please double-check your wiring and that each sensor works ne
individually before hooking up the two sensors at the same time.
Regards,
Sara
Reply
Peter Laneville
October 29, 2019 at 11:24 pm
Sara;
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 33/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Got both sensors working with one of the Dallas examples but they still
refuse to work with the multiple sensor code above???
Reply
Peter Laneville
October 30, 2019 at 5:52 pm
Sara;
I’ve checked the sensor waveform with an oscilloscope and data looks
good (clean transitions between 3.3 and 0 V).
I’ve noticed that the Dallas example also returns 0 devices found using
the “sensors.getDeviceCount()” command but the example then does an
address assignment by index and nds both devices and then continues
by reading the temperatures.
In the multiple sensor code above it looks like the code extracts the
address for each device found in a loop but since no devices are found….
Seems like either the DS18B20 sensors I have are defective (in not
correctly responding to the .getdevicecount command or the library has
an issue with the same command.
Anyway I’m moving forward as I can now read the sensor temperatures.
Reply
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 34/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Thomas Engelhardt
June 5, 2020 at 8:17 pm
I had the same experience and I can say for sure the sensors work ne
as I used them together with an Arduino Nano just before.
The lib apparently has an issue.
Reply
Abdul Fatah
February 20, 2020 at 8:39 am
Reply
Sara Santos
February 20, 2020 at 11:18 am
Hi.
Can you follow this and see if it solves your problem?
https://rntlab.com/question/failed-to-connect-to-esp32-invalid-head-of-
packet-0x2e/
Regards,
Sara
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 35/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Reply
DamienF
May 12, 2020 at 5:48 pm
Great tutorial, thanks for sharing. I incorporated for demo purposes most
of your code into a larger RTOS-based project and it works well. Running
on a nodeMCU ESP32-S on my local LAN wi .
Reply
Sara Santos
May 13, 2020 at 9:27 am
Great
Reply
Marcelo F
June 28, 2020 at 8:06 pm
Hi Sara,
I build that and i had for one DS180B20, the temperature -127C
Reply
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 36/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Sara Santos
June 29, 2020 at 10:53 am
Hi.
That usually means that there’s some issue with the wiring or power.
Regards,
Sara
Reply
Marcelo
June 29, 2020 at 11:33 am
Hi, i double check the wire (polarity PSU) and it is ok. I am using 5V
(~4.6V).
Reply
Sara Santos
June 29, 2020 at 2:13 pm
Reply
Marcelo
June 29, 2020 at 2:20 pm
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 37/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Hi Sara,
I am using NodeMCU-32, I changed to GPIO4 and still not working.
I was using GPIO34 before.
David
July 13, 2020 at 3:09 am
Thanks for the hint about the wiring. In my case, it was indeed a wiring
error. Same symptom (T=-127C) and sure enough, after I corrected a
wiring error it was xed. Thanks.
Reply
Ace
August 9, 2020 at 7:18 pm
Reply
RC
November 12, 2020 at 7:32 pm
For reliable operation, yes, use the 4.7k resistor on the waterproof
sensor also. I do.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 38/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Reply
Dunc
February 1, 2021 at 10:32 pm
I could not get it to run properly (kept getting -127) until I added the
resistor.
Reply
Felipe
September 7, 2020 at 8:28 pm
Hello, i’d like to know if its possible and how to add a chart/graph of how
the temperatures increases/decreases in real time.
Reply
Sara Santos
September 14, 2020 at 10:33 am
Hi.
Take a look at this tutorial: https://randomnerdtutorials.com/esp32-
esp8266-plot-chart-web-server/
Regards,
Sara
Reply
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 39/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Paul Nix
September 28, 2020 at 8:51 am
Hello, I would like to know wath can be the maximum cable length by 3,3v
supply from the esp32, and secondly if the use of 5v supply on the sensor
would be an issue for the esp32 input (witch is a 3,3v per datasheet).
Thank you
Reply
Elias Giannopoulos
September 28, 2020 at 6:34 pm
Dear Paul,
I have use 12 meters cable with 3.3V without any di erence using 1m
cable (sensors in same area gives same measurements +- sensor error).
I have use UTP cat6 cable, using 3 non twisted wires. Orange, green ,
blue.
Reply
Paul Nix
September 28, 2020 at 8:43 pm
Thank you for your reply Elias. My sensors are ordered, I will try it
soon.
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 40/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Reply
Strobistar
October 31, 2020 at 8:34 am
Hello!
Great tutorials for a learner!
I used your ESP32 tutorial and the serial output
(https://randomnerdtutorials.com/esp32-multiple-ds18b20-temperature-
sensors/) which worked great! My ve sensors are reporting back IDs and
I can see the measurements!
However, it seems that the webserver code above does only show one
temperature value although in the code, the ReadTemperature issue a
global temperature and Requests to all devices on the bus.
I am guessing that “ oat tempC = sensors.getTempCByIndex(0);” is
causing this, I’m imagining I could but a while loop around this, however
the imprints into the html is not in a while loop either.
Thanks for your advice!
Reply
Sara Santos
October 31, 2020 at 11:30 am
Hi.
You would need to create multiple variables to get the temperature
from the multiple sensors.
Then, modify the HTML to display multiple sensor readings.
Regards,
Sara
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 41/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Reply
Strobistar
October 31, 2020 at 11:48 am
Hi Sara,
it has been more than 20 years that I looked into programming code,
but indeed, I worked now with static variables and all my ve sensors
are now dumping their load into html.
Reply
Robert FOLKES
November 9, 2020 at 7:10 pm
Firstly a big thank you for these random nerd tutorials, my ‘smart pool’
project has temperature sensors, async web interface and email
reporting based originally on your excellent examples. However a
comment and a question:
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 42/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
One of my DS18B20s sits on the roof and we had a bad electrical storm a
couple of days ago. The webserver kept working, my email reports failed
as did some temperature sensors. I rebooted, then all the temperature
sensors failed – but the email reports came a back. I assumed the ESP
was partially fried, but when I did a full power cycle and software
upload,everything came back as usual – MIRACLE! All very strange, but
this does raise the question: what is best practice when connecting to an
external DS18B20s? This seems a good place to start
https://www.eevblog.com/forum/beginners/protecting-pic-inputs-
connected-to-ds18b20/msg182951/?
PHPSESSID=j8beh30uf8qsfraitsui45n6t6#msg182951 Further comment
appreciated.
Reply
Amr Khalifa
February 10, 2021 at 7:44 pm
Hi
I used two senors and when i uploaded the webserver codes i had
readings from only one sensor displayed on the webserver.
Any information on how to get readings from both sensors ?
Thanks
Reply
Strobistar
February 11, 2021 at 11:34 am
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 43/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Hi!
This code is to show only the rst sensor reading in both °C and °F (see
this line: oat tempC = sensors.getTempCByIndex(0);)
So either loop through your sensors, or work with the “mac” addresses
and launch those in the visualisation.
Good luck!
Reply
Dan
February 20, 2021 at 8:01 pm
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 44/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
String StrTempC;
String StrTempF;
String readDSTemperatureC() {
// Call sensors.requestTemperatures() to issue a global temperature and
Requests to all devices on the bus
sensors.requestTemperatures();
oat 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();
oat tempF = sensors.getTempFByIndex(0);
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 45/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
if(int(tempF) == -196){
Serial.println(“Failed to read from DS18B20 sensor”);
return “–“;
} else {
Serial.print(“Temperature Fahrenheit: “);
Serial.println(tempF);
}
return String(tempF);
}
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;
}
Temperature Celsius
%TEMPERATUREC%
°C
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(“temperaturec”).innerHTML =
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 46/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
this.responseText;
}
};
xhttp.open(“GET”, “/temperaturec”, true);
xhttp.send();
}, 1000) ;
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();
}, 1000) ;
)rawliteral”;
// Replaces placeholder with DHT values
String processor(const String& var){
//Serial.println(var);
if(var == “TEMPERATUREC”){
//return String(sensors.getTempCByIndex(0));
return StrTempC;
}
else if(var == “TEMPERATUREF”){
//return String(sensors.getTempFByIndex(0));
return StrTempF;
}
return String();
}
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
Serial.println();
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 47/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.println(“Connecting to WiFi”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println();
// Start server
server.begin();
}
void loop(){
StrTempC = readDSTemperatureC();
Serial.print(StrTempC);
Serial.print(” “);
StrTempF = readDSTemperatureF();
Serial.println(StrTempF);
}”
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 48/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
Reply
Leave a Comment
Name *
Email *
Website
Post Comment
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 49/50
22/3/2021 ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials
About Support Terms Privacy Policy Refunds MakerAdvisor.com Join the Lab
https://randomnerdtutorials.com/esp32-ds18b20-temperature-arduino-ide/?fbclid=IwAR1s6pcDKTPkJk0rpJIu2hik00LcV4-NVzRq2ekG0a9cfpKc9Zs… 50/50