Adequate temperature sensor for logging

Nick_Pyner:
There are really only two things to go wrong - the software, and the hardware. The latter includes the wiring.
If you are using established software, i.e. the standard libraries and a sketch known to be kosher from Hacktronics or the like, the problem has to be hardware. If the wiring is OK (?) the sensor may well be a dud - because it has suffered from recent user abuse. Trust me, the DS18B20 can take a lot of abuse, but your options for a working solution are limited.

So, what is the code? and do you have a virginal DS18B20 to hand?

Here is my full code... some of the stuff is from the thermistor code, so I have commented it out. A lot of the code is for driving my 7-seg display. My sensor code is all in the setup and loop functions at the bottom.

The sensor I am currently using is virginal.

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

#define A 16
#define B 8
#define C 4
#define D 2
#define E 1
#define FP 32
#define G 64

#define ZERO (A|FP|B|E|C|D)
#define ONE (B|C)
#define TWO (A|B|G|E|D)
#define THREE (ONE|A|G|D)
#define FOUR (FP|B|G|C)
#define FIVE (A|FP|G|C|D)
#define SIX (A|FP|G|C|D|E)
#define SEVEN (ONE|A)
#define EIGHT (ZERO|G)
#define NINE (A|B|C|D|FP|G)


//#define RANGE 56

int analogPin = 0;
int tempRead = 0;
int leftOn = 10;
int rightOn = 11;
int index;
int count = -1;
int sample = 0;

/*int temps[RANGE] = {715,707,698,689,680,670,661,651,641,631,621,611,600,590,579,568,557,546,535,523,512,500,489,477,466,454,442,431,419,407,395,384,372,361,349,338,327,316,305,294,283,273,263,253,243,233,224,214,205,196,188,179,171,163,156,148};*/
int pins[8] = {3,4,5,6,7,8,9,12};
byte encoded[10] = {ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};

byte addr[8];
OneWire ts(2);
DallasTemperature temp(&ts);


byte convertInt(int num)
{
   return encoded[(int)num]; 
}

void draw(byte digit)
{
   for (int i = 0; i <  7; i++)
    {
        
        if (((digit >> i) & 1) == 1)
        {
          digitalWrite(pins[i], LOW);
        }
        else
        {
           digitalWrite(pins[i], HIGH);
        }
    }
}

void writeNumber(int num){
    byte right;
    byte left;
    
    if (num > 10)
    {
      left = convertInt(num/10);
    }
    else
    {
      left = 0;
    }
    right = convertInt(num%10);
    
    if(num < 0)
    {
       digitalWrite(pins[7], HIGH); 
    }
    else
    {
       digitalWrite(pins[7], LOW); 
    }
    
    digitalWrite(rightOn, LOW);
    digitalWrite(leftOn, HIGH);
    
    draw(left);
    
    delay(10);
    
    digitalWrite(leftOn, LOW);
    digitalWrite(rightOn, HIGH);
    
    draw(right);
    
    delay(10);
}
void setup() {
  int i;
  for(i = 3; i < 13; i++) {
     pinMode(i, OUTPUT);
   }
   
   Serial.begin(115200);
   temp.begin();
   
  // Grab a count of devices on the wire

  int numberOfDevices = temp.getDeviceCount();

  // locate devices on the bus

  Serial.print("Locating devices...");

  Serial.print("Found ");

  Serial.print(numberOfDevices, DEC);

  Serial.println(" devices.");
  
    // report parasite power requirements

  Serial.print("Parasite power is: "); 

  if (temp.isParasitePowerMode()) Serial.println("ON");

  else Serial.println("OFF");

}

void loop() {

   if(count == -1 || count++ == 500)
   {
     Serial.print("Requesting temperatures...");
     temp.requestTemperatures();
     Serial.println("DONE");
     tempRead = temp.getTempCByIndex(0);
     /*if (tempRead == -127)
     {
        sample = 0; 
     }
     else
     {
        sample = tempRead; 
     }*/
     Serial.print("Temperature is: ");
     Serial.println(tempRead, DEC);
     count = 0;
   }
   
    writeNumber(sample);
}

afremont:
Complete 9DOF IMUs tend not to be real cheap either.

That might depend on precision/accuracy. I can get combined accel/gyro and separate compass modules cheap but the compass is only good to 1 or 2 degrees. I can get a set of those for < $20.

LukeTimothy:
Here is my full code... some of the stuff is from the thermistor code, so I have commented it out. A lot of the code is for driving my 7-seg display. My sensor code is all in the setup and loop functions at the bottom.

The sensor I am currently using is virginal.

OK. I understand that a lot of that is for the display, but even the stuff that looks like it might be for the temperature is incomprehensible.

Attached is a plain vanilla DS18B20 programme lifted from Hacktronics. It is probably the same as the opne included with the library. You might try it, if only to ensure your gear is OK. It has just occurred to me that there might be more than one DallasTemperature.h. The first three lines of mine read

#ifndef DallasTemperature_h
#define DallasTemperature_h
#define DALLASTEMPLIBVERSION "3.7.2"

and I guess it came from Hacktronics but there is no author note.

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

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

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = { 0x28, tra-la-la USE THE ADDRESS FINDER FOR YOUR CODE, 0xFE };

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);
}

void loop(void)
{ 
  delay(2000);
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  }

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
     Serial.println(tempC);
  }

#define DALLASTEMPLIBVERSION "3.7.2"

and I guess it came from Hacktronics but there is no author note.

This is the source - MilesBurton.com -