Arduino DS18B20 with DallasTemperature: Wiring, Code and Simulator
To build this Arduino DS18B20 with DallasTemperature project you need an Arduino Uno and a temperature sensor DS18B20 and a 4.7 kΩ resistor. OneWire + DallasTemperature read a DS18B20 thermometer on one pin, with its 4.7 kΩ pull-up. Make the 5 connections in the wiring table, upload the Arduino C++ code, and select the sensor and move its Temperature slider while it runs.
Open this circuit in the free Arduino Uno simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | Temperature Sensor DS18B20 | 1-Wire digital thermometer: DQ to a pin with a 4.7 kΩ pull-up to 5 V, VDD to 5 V, GND. Read it with OneWire + DallasTemperature. Legs GND, DQ, VDD. |
| 1 | 4.7 kΩ resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno GND | Temperature Sensor DS18B20 GND |
| 2 | Arduino Uno 5V | Temperature Sensor DS18B20 VDD |
| 3 | Arduino Uno pin 2 | Temperature Sensor DS18B20 DQ |
| 4 | 4.7 kΩ resistor leg 1 | Temperature Sensor DS18B20 DQ |
| 5 | Arduino Uno 5V | 4.7 kΩ resistor leg 2 |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a temperature sensor DS18B20 and a 4.7 kΩ resistor from the parts palette.
- Wire 1. Connect Arduino Uno GND to Temperature Sensor DS18B20 GND.
- Wire 2. Connect Arduino Uno 5V to Temperature Sensor DS18B20 VDD.
- Wire 3. Connect Arduino Uno pin 2 to Temperature Sensor DS18B20 DQ.
- Wire 4. Connect 4.7 kΩ resistor leg 1 to Temperature Sensor DS18B20 DQ.
- Wire 5. Connect Arduino Uno 5V to 4.7 kΩ resistor leg 2.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Select the sensor and move its Temperature slider while it runs.
Arduino C++ code
// OneWire + DallasTemperature: read a DS18B20 digital thermometer on one data pin.
// The DQ line needs a 4.7 kOhm pull-up to 5 V, as on a real board.
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire bus(2);
DallasTemperature sensors(&bus);
void setup() {
Serial.begin(9600);
sensors.begin();
Serial.print("Sensors found: ");
Serial.println(sensors.getDeviceCount());
}
void loop() {
sensors.requestTemperatures();
float c = sensors.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(c, 2);
Serial.println(" C");
delay(1000);
}
What to try
Select the sensor and move its Temperature slider while it runs.
Frequently asked questions
How do I wire the DS18B20 with DallasTemperature project on an Arduino Uno?
Make 5 connections: Arduino Uno GND to Temperature Sensor DS18B20 GND; Arduino Uno 5V to Temperature Sensor DS18B20 VDD; Arduino Uno pin 2 to Temperature Sensor DS18B20 DQ; 4.7 kΩ resistor leg 1 to Temperature Sensor DS18B20 DQ; Arduino Uno 5V to 4.7 kΩ resistor leg 2.
What parts do I need for this Arduino project?
An Arduino Uno and a temperature sensor DS18B20 and a 4.7 kΩ resistor.
Can I simulate this Arduino project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.
What does the code do?
OneWire + DallasTemperature read a DS18B20 thermometer on one pin, with its 4.7 kΩ pull-up.
More Arduino Uno projects
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator