Problems getting feedback from DS18B20 thermometer using pregen onewire code

Hi Guys,

Im pretty new to the Arduino and am encountering some sticking points that I dont really understand how to get past.

I am trying to get a basic temperature reading from the digital waterproof sensor I have but whenever I upload the code the serial monitor gives back the number 85.00 over and over again. My eventual goal is to be notified when a specific temperature has been reached, 60C to be exact.

I have uploaded the code, pictures of my circuit (edit - in the pictures it is shown on pin 5, we have now moved it to pin 10 so this is not a unknown mistake) and of the serial monitor below. Thanks for your help.

new code

#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) {
  int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
  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 a DS18S20 family device.\n");
  }
  else if ( addr[0] == 0x28) {
      Serial.print("Device is a DS18B20 family device.\n");
  }
  else {
      Serial.print("Device family is not recognized: 0x");
      Serial.println(addr[0],HEX);
      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();
  LowByte = data[0];
  HighByte = data[1];
  TReading = (HighByte << 8) + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit
  if (SignBit) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  Whole = Tc_100 / 100;  // separate off the whole and fractional portions
  Fract = Tc_100 % 100;


  if (SignBit) // If its negative
  {
     Serial.print("-");
  }
  Serial.print(Whole);
  Serial.print(".");
  if (Fract < 10)
  {
     Serial.print("0");
  }
  Serial.print(Fract);

  Serial.print("\n");
}

"85" is the default temperature on power-up, so the sensor is working, but for some reason it is not actually reading the temperature. I can't make much sense of your photos - a diagram showing connections with pin numbers and the resistor value would be more useful. In the meantime, search the net for more ideas. Here is one discussion: Solution to DS18B20 random 85°C measurements - Sensors - Arduino Forum

espezel:
I upload the code the serial monitor gives back the number 85.00 over and over again.

An 85 indicates a power-on reset. This can happen by simply calling for a reading before the sensor is ready i.e. at the start of a programme, or or too frequently, both of which are easily fixed, but I think it is more serious in your case and may be caused by the code being verbose junk. Since you are using the Dallas Temperature sensor, you will be better off using the Dallas Temperature library, it will enable you to swim with the tide, and save you a lot of grief. A basic example using that system is below. There are other similar methods, but this is what I use, and I believe it uses the least amount of code.

Read the last three lines of the preliminary comment twice.

/* Basic 3xDS18B20 code for serial monitor, bluetooth, Excel or w.h.y.
Derived from Hacktronics. USE THEIR ADDRESS SNIFFER and substitute your 
numbers. Use Hacktronics connections diagram. 
http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
Stay away from using parasite power
-127C means bad connection
85 means you haven't gotten a read yet, probably just the wrong order of commands
*/

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
  
byte Thermo1[8] = {0x28, 0x39, 0xFD, 0x50, 0x04, 0x00, 0x00, 0X69};
byte Thermo2[8] = {0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};
byte Thermo3[8] = {0x28, 0x62, 0xA5, 0x2D, 0x04, 0x00, 0x00, 0x21};   

float tempC,Temp1,Temp2,Temp3,diff;  

void setup(){

  Serial.begin(9600);
  sensors.begin();

  delay(500);//Wait for newly restarted system to stabilize

  sensors.setResolution(Thermo1, 12); 
  sensors.setResolution(Thermo2, 12);
  sensors.setResolution(Thermo3, 12);
}

void loop() {
 sensors.requestTemperatures();  // call readings from the addresses
  Temp1 = sensorValue(Thermo1);
  Temp2 = sensorValue(Thermo2);  
  Temp3 = sensorValue(Thermo3); 
       diff = Temp2 - Temp1;

Serial.print("      Temp1 = ");
Serial.print(Temp1);
Serial.print("      Temp2 = "); 
Serial.print(Temp2);
Serial.print("      difference = ");
Serial.print(diff);
Serial.print("      Temp3 = ");
Serial.println(Temp3);

delay(1000);
}

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

Thanks so much for your help!

I got it working using the Dallas coding and realised that i was actually running off parasite power which was not enough and this it kept defaulting back to 85. The new code I used is below.

My next step is to try and recieve a text when a certain temperature has been reached. Im trying to blend the codes given by Temboo for this but if you had any advice or tips to help that would be amazing

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
 
#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
 
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
 
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
 
DeviceAddress insideThermometer = { 0x28, 0x34, 0x39, 0x06, 0x06, 0x00, 0x00, 0x80 }; //change to your address
DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };
 
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  sensors.setResolution(dogHouseThermometer, 10);
}
 
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}
 
void loop(void)
{
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
  Serial.print("Outside temperature is: ");
  printTemperature(outsideThermometer);
  Serial.print("\n\r");
  Serial.print("Dog House temperature is: ");
  printTemperature(dogHouseThermometer);
  Serial.print("\n\r\n\r");
}

That's fair enough, you will see that the code I posted is essentially the same but streamlined for (I think) better integration into future work. It is derived from the same tutorial.

To get the signal, I would just use a flag

Int flag = 0
loop
if temp>59.99 and flag = 0 then send text. Flag =1
if temp<60.00 then flag = 0

I think that would cover it, but there may be more elegant means!