fbpx

Procedure

Schematic:

The sensor can operate in two modes:

Normal mode:

A 3-wire connection is needed. You provide power to the VDD pin. Here’s the schematic you need to follow:

Parasite mode:

You only need data and GND. The sensor derives its power from the data line. In this case,here’s the schematic you need to follow:

To interface with the DS18B20 temperature sensor, you need to install the One Wire library by Paul Stoffregen and the Dallas Temperature library. Follow the next steps to install those libraries.

  • Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.

  • Type “OneWire” in the search box and install the OneWire library by Paul Stoffregen.

Programming:

#include <OneWire.h>
#include <DallasTemperature.h>/
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
sensors.begin();
}
void loop(void)
{
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print(“Celsius temperature: “);
// Why “byIndex”? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(” – Fahrenheit temperature: “);
Serial.println(sensors.getTempFByIndex(0));
delay(1000); }

After uploading the code, open the Arduino IDE Serial Monitor at a 9600 baud rate. You should get the temperature displayed in both Celsius and Fahrenheit: