still under construction, but feel free to explore :)
HOME / Articles/Tutorials / Electrical / Electronics Articles / Arduino Board Articles / Arduino General Articles / Dallas DS18b20 1-Wire Digital Temperature Sensor

Dallas DS18b20 1-Wire Digital Temperature Sensor

Example of using Dallas DS18b20 Digital Temperature Sensor and One Wire with Arduino

For specific arduino boards and categorized examples use the appropriate link in the previous page

What is Dallas DS18b20 Digital Temperature Sensor

DS18B20 is a 1-Wire digital temperature sensor from Maxim IC. It can measure degrees with 9 to 12-bit precision, from -55C to 125C (+/-0.5C). Each sensor has a unique 64-Bit Serial numbersent with it’s data, which allows for a huge number of sensors to be used on one data bus and define where the value is coming from.

What is 1-Wire protocol

Maxim (former Dallas Semiconductor) produces a family of devices that are controlled through a proprietary 1-wire protocol. Info and laatest version of the protocol can be found here:

There are number of sites where you can get detailed info for 1-wire protocol(check Links at the bottom). There is another library called Dallas Temperature Control Library that makes things even easier. Info and dowload link for it can be found here:

It supports:

  • DS18B20
  • DS18S20
  • DS1822

Using this library one can use the chip and get temperature readings with a few lines of code.

How do we connect it to the Arduino

We need just one 4K7 resistor.


The code

This is a simple code that outputs temperature readings to the serial port. You can see the readings using the Serial Monitor. Note that you will need to put bot OneWire and DallasTemperature librariles into your Libraries folder.

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

void setup(void)
  // start serial port
  // Start up the library
  sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement

void loop(void)

The result :)

(an exmple with arduino nano ds18b20, LDR and BT modem transmitting to Android device)



Author: DjoDjo