One-wire temperature sensor reading constant temp

I'm using a Dallas one-wire temperature sensor that I believe I've correctly connected using the datasheet(http://datasheets.maxim-ic.com/en/ds/DS18S20.pdf) and the diagram in Peter Anderson's code (http://www.phanderson.com/arduino/ds18b20_1.html).

I'm using code found on this forum (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1199313338) to read the value off the sensor.

When I do this, I get a constant reading of 3 degC off the sensor (its much warmer than that in my room). If I look at the raw values that come off the sensor, the temperature part never changes.

I think my physical setup is correct as any other configuration doesn't return anything on the bus. Any idea what might be causing the problem? Let me know if I'm missing any important information.

out of Curiosity - have you tried to artificially modify the temp to see if the value changes? In example, apply an ice-cube to the sensor and watch the values? If it changes, then that will help you narrow down where the issue might be.

I've exhaled and held the sensor with no change.

Could you include the actual code you are using? There is lots of code on the post you referenced and not all of it works.

I'm using a combination of the OneWire code from the playground (Arduino Playground - OneWire) and the bit shifting from that forum post.

#include <OneWire.h>

// DS18S20 Temperature chip i/o

OneWire ds(12);  // on pin 10

void setup(void) {
  // initialize inputs/outputs
  // start serial port
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      Serial.print("No more addresses.\n");
      ds.reset_search();
      return;
  }

  Serial.print("R=");
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

  if ( addr[0] != 0x10) {
      Serial.print("Device is not a DS18S20 family device.\n");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("P=");
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print( OneWire::crc8( data, 8), HEX);
  Serial.println();
  
  int rawtemp = (data[1] << 8) + data[0]; 
  double tempc, tempf;
  tempc = (double)rawtemp / 16.0;
  tempf = (tempc * 1.8) + 32.0;
  
  Serial.print("T=");
  Serial.println(tempf,DEC);
}

With this code and applying heat:

R=10 E1 D8 35 1 8 0 91 P=1 35 0 4B 46 FF FF 6 10 5C  CRC=5C

T=37

No more addresses.
R=10 E1 D8 35 1 8 0 91 P=1 36 0 4B 46 FF FF 10 10 DF  CRC=DF

T=38

Applying an ice cube:

R=10 E1 D8 35 1 8 0 91 P=1 2B 0 4B 46 FF FF 6 10 B1  CRC=B1

T=36

No more addresses.

The 1 deg shift either directly doesn't seem right.

I've attached a picture of my circuit with annotations in case I hooked it up wrong:

Thanks for the suggestions so far

Hey, Stubbie,

I think I see what's going wrong. The raw data seems reasonable, so I checked the DS18S20 data sheet and I think the value "rawdata" indicates temperature at 1/2 degree (celsius) chunks, and not 1/16 degree. If you change the one line to

tempc = (double)rawtemp / 2.0;

you get more plausible temperatures of 26.5C = 79.7F, 27.0C = 80.6F, and 21.5C = 70.7F.

For confirmation, look at "Table 1: Temperature/Data Relationship" in the datasheet.

Mikal

Thats exactly what it was!

Thats what I get for copying code and not reading the datasheet. Thanks