1

About 30 minutes of data

Here's the code

#include <OneWire.h> 

int DS18S20_Pin = 3; //DS18S20 Signal pin on digital 3
unsigned long startTime = 0;
#define MEASURE_PERIOD 250
//Temperature chip i/o
OneWire ds(DS18S20_Pin);  // on digital pin 3

void setup() {
  Serial.begin(115200);
}

void loop() {
  if((millis() - startTime) >= MEASURE_PERIOD)
    {
        startTime += MEASURE_PERIOD;
        float temperature = getTemp();
        Serial.println(temperature);
    } //just here to slow down the output so it is easier to read

}


float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

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

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }

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

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


  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }

  ds.reset_search();

  //byte MSB = data[1];
 // byte LSB = data[0];

  float tempRead = ((((int)data[1]) << 8) | data[0]); //using two's compliment
  float TemperatureSum = tempRead / 16;

  return TemperatureSum;

}
3
  • 4
    What are X and Y axes on graph? – Darko Apr 16 '16 at 14:53
  • X time, Y temperature – Gabriele Giordano Apr 16 '16 at 16:03
  • Y is standardized temperature – Gabriele Giordano Apr 16 '16 at 16:03
1

Examine your code closely. It appears that you are partially implementing extended resolution calculations in this line of code:

  float TemperatureSum = tempRead / 16;

In the DS18S20 specifications the extended resolution equation used is:

 TEMPERATURE = TEMP_READ * 0.25 - ((COUNT_PER_C - COUNT_REMAIN) / (COUNT_PER_C))

Where COUNT_PER_C is a DS18S20 register containing a value of up to 16. Maybe that is where 16 originated?

I believe what you want to do is divide the recovered value by 2.0 base on table 1 from the DS18S20 specifications:

  float TemperatureSum = tempRead / 2.0;

Don't forget the "." in case the compiler you are using decides to do integer math dripping the "float" part before assigning it to TemperatureSum.

7
  • I'm not sure I understood what you are suggesting. If i put 2.0 I have values like that: 165 164,5 165 – Gabriele Giordano Apr 18 '16 at 8:19
  • The DS18S20 (datasheets.maximintegrated.com/en/ds/DS18S20.pdf) specification says the temperature is returned in degrees centigrade and is in 1/2 degree increments (table 1, page 6). There might be other important details. But you said you did not see enough change. Dividing by 16 instead of 2 would explain that. – st2000 Apr 18 '16 at 12:52
  • Your values do not make sense. In your graph when you measure your skin temperature you get 0.96 C when you divide by 16. But in your comment above when you divide by 2 you are getting 165 C The value 0.96 * 16 is no where near 165 * 2. Carefully consider how you are posting so that we can find the problem faster... Oh, I get it! You're using commas as decimal points. Still, that doesn't explain the 0.96. But 96 * 16 ~= 165 * 2. – st2000 Apr 18 '16 at 12:58
  • Also, consider the possibility the DS18S20 packaging is slow to respond and the possibility the DS18S20 is internally computing an average in an attempt to reduce noise and increase resolution. In this (electronics.stackexchange.com/questions/186449/…) stackexchange answer a ti.com TO92 package temperature sensor response is show. It appears to take 6 to 10 seconds to report the correct oil bath temperature. – st2000 Apr 18 '16 at 13:13
  • 0.96 is not the temperature. It's the standardized temperature: value/max(list of values) – Gabriele Giordano Apr 19 '16 at 9:34
0

Try using Dallas Temperature Control Library for DS18S20. (Click Here, Download Library). Its simple and easy to use, and it comes with examples.

Here is tutorial.

Hope it helps.

2
  • I'm curious why a person found this not useful – Gabriele Giordano Apr 17 '16 at 7:40
  • I didn't understand how can I put it at 12bits – Gabriele Giordano Apr 19 '16 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.