Arduino 1-Wire Device Libraries

DS18S20 Library


DS18S20 in a TO-92 Package

The Dallas-Maxim DS18S20 is a digital temperature probe in a TO-92 package. This library supports only a single mode of operation, and only in non-parasitic mode. See the Dallas-Maxim DS18S20 datasheet for more information about this device and its capabilities. There are numerous examples on the Internet describing how to interface this and similar temperature sensors with an Arduino. There is nothing noteworthy about this particular library apart from its consistent interface with the other libraries found here. Additionally, a number of examples found on Arduino reference pages do not correctly handle the twos-compliment value and will not report valid temperature values below 0°C. This library does correctly handle negative temperature values.

To use this library in a sketch,

  1. Include the OneWire.h and DS18S20.h header files.
  2. Call the ds18s20.begin() method in the setup() method of the sketch.
  3. Then, whenever a temperature value is required, call the ds18s20.update() method.
  4. Call the ds18s20.isError() method to determine if the update succeeded.
  5. And, if successful, call the ds18s20.getTemperature() method to return the temperature value in degrees Celsius.

Like the other device libraries in this collection, there is also a getTimestamp() method that returns the value of the Arduino millis() function at the time the ds18s20.update() method was called. This can be useful to compute elapsed milliseconds between subsequent updates.

The example code demonstrates the use of this library to continuously read a DS18S20 sensor and print its value in both degrees Celsius and degrees Fahrenheit to the serial port.


<<Previous Page | Index | Next Page>>