3.18. DS18B20 Digital Thermometer
| Description | In this project, learners will build a precise digital thermometer using the DS18B20 one-wire temperature sensor. Unlike simple analog temperature sensors, the DS18B20 communicates digitally and provides accurate readings in degrees Celsius directly. This project introduces the 1-Wire communication protocol and demonstrates how multiple digital sensors can share a single data wire, which is a key technique in professional temperature monitoring systems. |
|---|---|
| Use case | This project is connected to real-world uses such as: The DS18B20 provides highly accurate digital temperature readings. Its 1-Wire protocol allows multiple sensors to share one data line, making it ideal for temperature monitoring in greenhouses, data centres, and food storage systems. |
Components (Things You will need)
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
Building the circuit
Things Needed:
- Arduino Uno
- DS18B20 Temperature Module / Sensor
- 4.7kΩ Resistor
- Breadboard
- Jumper Wires
- Arduino USB Cable
Mounting the component on the breadboard and wiring the circuit
Step 1: Identify each component listed in the Required Components table before assembling the circuit.
-
Place the DS18B20 Temperature Sensor and the 4.7kΩ resistor on the breadboard.
-
Connect the DS18B20 Temperature Sensor:
-
Connect the VDD (Red) wire to the 5V pin on the Arduino Uno.
-
Connect the GND (Black) wire to the GND pin on the Arduino Uno.
-
Connect the DQ (Yellow/Data) wire to Digital Pin 2 on the Arduino Uno.
-
Connect the 4.7kΩ pull-up resistor by connecting one end to Digital Pin 2 (DQ) and the other end to the 5V pin. This resistor is required for reliable 1-Wire communication between the Arduino Uno and the DS18B20 sensor.
-
Ensure all GND connections share the same ground line before powering the circuit.
-
Verify that the 4.7kΩ pull-up resistor is correctly connected between Digital Pin 2 and 5V, and check all wiring before connecting USB power.

Make sure to connect the Arduino USB cable to the Arduino board.
PROGRAMMING
Step 1: Open your Arduino IDE. See how to set up here: Getting Started.
Step 2: Write the complete program implementing the system logic with appropriate pin definitions, setup configuration, and the main control loop.
// DS18B20 Digital Thermometer
// Requires: OneWire and DallasTemperature libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
Serial.println("DS18B20 Thermometer Ready");
}
void loop() {
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
if (tempC == DEVICE_DISCONNECTED_C) {
Serial.println("Error: Sensor not connected!");
} else {
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.println(" C");
}
delay(1000);
}
Step 3: Save your code. See the Getting Started section
Step 4: Select the arduino board and port _See the Getting Started.
Step 5: Upload your code.
CONCLUSION
After the program starts, the Serial Monitor displays the temperature measured by the DS18B20 temperature sensor every second.
When you hold the sensor between your fingers, the measured temperature gradually increases as the sensor detects the warmth from your hand. When you remove your hand and blow cool air across the sensor, the temperature reading gradually decreases within a few seconds as the sensor responds to the lower temperature. This demonstrates the DS18B20's ability to provide accurate, real-time digital temperature measurements.





