DS18B20 Web Server

Interface Multiple DS18B20s with ESP32 & Display Values Using Web Server

If you’ve ever envisioned having sensors placed throughout your home and garden, continuously reporting temperature data to a central server, then this IoT project is the perfect starting point for you! 

Using the ESP32 as the control device, this project effortlessly connects to your existing WiFi network and sets up a Web Server. Whenever a device connects to this web server, the ESP32 reads temperature data from multiple DS18B20 Temperature sensors. It then presents this data on the connected device’s web browser through a user-friendly interface.

Multiple DS18B20s On Single Bus

One of the standout features of the DS18B20 temperature sensor is its ability to support multiple sensors on the same 1-Wire bus. Each DS18B20 has a unique 64-bit serial code assigned during manufacturing, making it easy to distinguish between them.

This capability offers a significant advantage when you need to monitor temperature across a wide area using numerous DS18B20 sensors. In this tutorial, we’ll explore how to leverage this feature to control multiple DS18B20 sensors spread over a large area.

Top of Form

Wiring Multiple DS18B20 Sensors to ESP32

Wiring multiple DS18B20 sensors to an ESP32 is straightforward:

  1. Connect all the DS18B20 sensors in parallel by joining their VDD (power), GND (ground), and signal pins together.
  2. Connect the VDD pin of the DS18B20 sensors to the 3.3V output on the ESP32.
  3. Connect the GND pin of the DS18B20 sensors to the ground (GND) on the ESP32.
  4. Connect the signal pin (data) of the DS18B20 sensors to digital pin 15 on the ESP32.
  5. Add a single 4.7k pull-up resistor between the signal pin and the power pin of the DS18B20 sensors to ensure stable data transfer across the entire bus.

Here are the key specifications of the DS18B20 temperature sensor:

  • Utilizes one-wire bus communication for easy integration
  • Supports a power supply range from 3.0V to 5.5V for versatile usage
  • Operates effectively within a wide temperature range from -55ºC to +125ºC
  • Offers high accuracy with a tolerance of +/-0.5 ºC within the range of -10ºC to 85ºC

For further details, refer to the DS18B20 datasheet.

Parts Required


To complete this tutorial, you’ll need the following components:

  1. ESP32 development board (you can refer to the Best ESP32 development boards for options)
  2. DS18B20 temperature sensor (one or multiple sensors) – make sure to use the waterproof version
  3. 4.7k Ohm resistor
  4. Jumper wires for connections
  5. Breadboard for prototyping

Preparing the Arduino IDE

To prepare your Arduino IDE for programming the ESP32, you’ll need to install an add-on. Follow these steps to set it up:

  1. Open your Arduino IDE.
  2. Go to File > Preferences (on Windows) or Arduino > Preferences (on macOS).
  3. In the “Additional Board Manager URLs” field, add the following URL:

arduinoCopy code

https://dl.espressif.com/dl/package_esp32_index.json

  1. Click OK to close the Preferences window.
  2. Now, navigate to Tools > Board > Boards Manager.
  3. In the Boards Manager, search for “ESP32” using the search bar.
  4. You should see an option called “esp32 by Espressif Systems.” Click on it and then click the “Install” button.
  5. Once the installation is complete, close the Boards Manager.

Now, your Arduino IDE is ready to work with the ESP32. You can select the ESP32 board from the Tools > Board menu and start programming!

Installing Libraries


To interface with the DS18B20 temperature sensor, you’ll need to install the OneWire library by Paul Stoffregen and the Dallas Temperature library. Follow these steps to install the libraries:

  1. Open your Arduino IDE and navigate to Sketch > Include Library > Manage Libraries. This will open the Library Manager.
  2. In the search box, type “onewire” and install the OneWire library by Paul Stoffregen.
  3. Next, search for “Dallas” and install the DallasTemperature library by Miles Burton.
  4. After installing the libraries, restart your Arduino IDE to ensure that the changes take effect.

Once you’ve installed the necessary libraries, you can proceed to upload the code to your ESP32. The code provided below reads temperature data from the DS18B20 sensor and outputs the readings to the Arduino IDE Serial Monitor.

Code



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

// Define the GPIO pin where the DS18B20 is connected
const int DS18B20_Pin = 4;     

// Initialize a OneWire instance to communicate with OneWire devices
OneWire oneWire(DS18B20_Pin);

// Initialize a DallasTemperature instance to interact with the DS18B20 sensor
DallasTemperature sensors(&oneWire);

void setup() {
  // Start serial communication at 115200 baud rate
  Serial.begin(115200);
  
  // Start the DS18B20 sensor
  sensors.begin();
}

void loop() {
  // Request temperature readings from the DS18B20 sensor
  sensors.requestTemperatures(); 
  
  // Read temperature in Celsius and Fahrenheit
  float temperatureC = sensors.getTempCByIndex(0);
  float temperatureF = sensors.getTempFByIndex(0);
  
  // Print temperature readings to the serial monitor
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.print(" ºC\t");
  Serial.print(temperatureF);
  Serial.println(" ºF");
  
  // Wait for 5 seconds before taking the next reading
  delay(5000);
}

Obtaining temperature readings from DS18B20 temperature sensors can be accomplished in various ways, but if you’re only working with a single sensor, the code provided here offers a straightforward and uncomplicated approach.

Applications:

  1. Temperature Monitoring: Monitoring temperature in various environments such as homes, offices, warehouses, and industrial settings.
  2. Cold Chain Management: Ensuring the proper temperature of perishable goods during storage and transportation.
  3. HVAC Systems: Integrating temperature monitoring into heating, ventilation, and air conditioning systems for efficient control.

Advantages:

  • Accuracy: DS18B20 sensors provide precise temperature readings for reliable monitoring.
  • Versatility: Can be deployed in a wide range of applications due to their small size and compatibility with different platforms.
  • Remote Monitoring: Web server integration enables remote access to temperature data for real-time monitoring and analysis.

    Leave a Reply

    Your email address will not be published.

    Need Help?