Dallas DS18S20 temperature sensor

I am trying to interface the Dallas DS18B20 onewire temp sensor and can’t seem to get a reading. Perhaps I am doing something wrong. Here is the code and schematic I am using.

#include <OneWire.h>

/* DS18S20 Temperature chip i/o

 */

OneWire  ds(10);  // 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=");  //R=28 Not sure what this is
  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] != 0x28) {
      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();
}

Here are the readouts I am getting. Any suggestions?

R=0 0 0 0 0 0 0 40 CRC is not valid!
R=0 0 0 0 0 0 0 C0 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!
R=0 0 0 0 0 0 0 C0 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!
R=0 0 0 0 0 0 0 C0 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!
R=0 0 0 0 0 0 0 C0 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!
R=0 0 0 0 0 0 0 C0 CRC is not valid!
R=0 0 0 0 0 0 0 40 CRC is not valid!

Thanks!!!

Try this:-

#include <OneWire.h>

/* DS18S20 Temperature chip i/o
 
 */

OneWire  ds(10);  // on pin 10
byte tempSensorAddress[8];
byte portAddress[8];

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



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

void findDevices(){
  boolean done = false;
  byte i;
  byte addr[8];
 
  while(!done) {
  if ( !ds.search(addr)) {
//     if(tempSensorAddress != 0) {Serial.print("Temprature Sensor at "); Serial.println(tempSensorAddress, HEX); }
//     if(portAddress != 0) {Serial.print("I/O port at "); Serial.println(portAddress, HEX); }
      Serial.println("No more devices found");
      ds.reset_search();
        done = true;
  }
   else
   {
     // display address
       Serial.print("Address = ");
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }
  Serial.println(" ");
    if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
    }
      else {
        if ( addr[0] == 0x3B) {
      Serial.print("Device is DS1825\n");
      for( i = 0; i < 8; i++) {
       tempSensorAddress[i] =  addr[i];
      }
     }
   if ( addr[0] == 0x3A) {
      Serial.print("Device is DS1413\n");
      for( i = 0; i < 8; i++) {
       portAddress[i] =  addr[i];
      }
     }
         }  // end of else for CRC not valid
  }         // end of else for got no more addresses
   }        // end of while not done
}

void readTemp(){
  byte data[12];
   ds.reset();
  ds.select(tempSensorAddress);    
  ds.write(0x44);         // Convert temp
  
  delay(1000);
  ds.reset();
  ds.select(tempSensorAddress);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print(" ");
  for ( int 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();
}

Also add a 4K7 pull up resistor to pin 10.

Also add a 4K7 pull up resistor to pin 10.

By the way... this is not optional!

Although probably not relevant to your problem, just a quick note: with that wiring don't need parasitic power.