new OneWireTempSensor library

I have created a library for use with a string of Dallas Semiconductor
DS18S20 temperature sensors. The library allows searching for sensors
on the One-Wire bus, and for obtaining the temperature
of each sensor in degrees Celsius or Fahrenheit, as floating-point numbers.

The library creates a subclass of the OneWire library object.

The library information is at

The active link to the library is

The library works great. I'm using the DS818S20 which has a 9-bit converter. The library only seems to support 12-bit conversion. Ideally, the library could detect (or set manually) if 9 or 12 bit is needed. If I add it - should I sent a patch? (New to arduino and how things work around here.)

For anyone who wants to hacking this into their code - the 9-bit conversion is simple. In the DallasTemperature::getTemperature method, change:

float temp = (6 * reading) + reading / 4;    // multiply by (100 * 0.0625) or 6.25
return temp/100;    // Divide by 100 to gain decimal.


float temp = (float)reading / 2;
return temp;

Basically, a value of 50 (0x32) is 25.0C. A value of 51 (0x33) is 25.5C.

Just realized that the original library is supposed to be for the DS18S20 - so I’m not sure why i needed to edit it.

Looking at the spec sheet there is also a way to calculate a higher resolution temperature readings. The library currently only reads bytes 0 and 1 to get the temperature, so it would need to be extended to read byte 6 (CountPerC) and byte 7 (CountRemain).

The calculation is:

int CountRemain; // todo: read byte 6
int CountPerC; // todo: read byte 7 (always 16)
int TReading = (HighByte << 8) + LowByte;  // merge hi,low bytes
int TTemp = TReading >> 1;  // remove fractional bit e.g. 25.5 to 25
float THiRes = (float)TTemp-0.25+((float)(CountPerC-CountRemain)/CountPerC);

I think you missed the fact that the library already does read the CountRemain and CountPerC data from the DS18S20 and does the calculation you describe. See lines 89-92 of OneWireTempSensor.cpp.

Ah. Somehow I was using an older library. It was called “DallasTemperature” and must be ancient since that brand was replaced by Maxim in 2007.

I’m now getting correct results with the your sample code. Thanks.

btw, the docs say that Serial.print() cannot handle floats, but it works fine for me. e.g.

  // loop through all the DS1820 temp sensors on the bus
  for (currdev = 0; currdev < numdevs; ++currdev) {
    /* get the temperature */
    real_temp = sensors.getTempC(currdev);
    Serial.print("Temperature of device ");
    Serial.print(" is ");


Temperature of device 0 is 27.94
Temperature of device 0 is 27.87
Temperature of device 0 is 27.81
Temperature of device 0 is 27.69

Hey mate,

“DallasTemperature” (The control library) is only a few months old. It’s designed to do what you’ve just created.

Maxim/Dallas, it was just a name I picked.