🌡 Connecting ds18b20 to Arduino (temperature sensor)

🌡 Connecting ds18b20 to Arduino (temperature sensor)

Daniil Zhuk

The DS18B20 temperature sensor is a digital temperature sensor. This means that you can measure the temperature using a very simple circuit. It communicates with a common bus, which means that you can connect multiple devices and measure their values using only one Arduino digital output.
The sensor has only three contacts, as you can see in the following figure. The DS18B20 is also available in a waterproof version.

Here are some of the main features of the DS18B20 temperature sensor:

  • Communication over a single-wire communication bus
  • Operating temperature: -55ºC to 125ºC
  • Accuracy +/- 0.5 ºC (between a range from -10ºC to 85ºC)
Required materials:
  • Arduino (Uno, Nano, Mega, ...)
  • DS18B20 sensor
  • Breadboard
  • Wires
  • 4,7 kOhm resistor

3-wire connection required. Here is the scheme you must follow:

The black part in the diagram is a temperature sensor.

You will need to install the OneWire and DallasTemperature libraries.

  • You must have .zip archives of libraries.
  • Add via “sketch” - “libraries” - ”add zip library”

Download the following code to the Arduino board.

#include <OneWire.h>
#include <DallasTemperature.h>
// ds18b20 is connected to second digital pin on Arduino
#define ONE_WIRE_BUS 2
// Setting up a oneWire instance to communicate with any devices
OneWire oneWire(ONE_WIRE_BUS);
//transmitting onewire link to temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
 // Sensor begin

void loop(void){
 // Call sensor.requestTemperatures () to issue global temperature and queries to all devices on the bus.
 Serial.print("Celsius temperature: ");
 //You can have more than one chip on the same bus. 0 refers to the first IC on the wire
 Serial.print(" - Fahrenheit temperature: ");
Finally, you should open the Arduino IDE serial monitor at 9600 baud, and you will see the temperature displayed in both Celsius and Fahrenheit:
Share this article with a friend who also loves electronics.
And write in the comments if there are difficulties.

Add a comment

* Comments must be approved before being displayed.