10kOhm thermistor jumble mess


i am using a 10kOhm thermistor using the following code wich works fine

/* 
   ReadThermistorLLAP
   Reads the temperature via a Thermistor set up
   Switches the LED on when the temperature goes over 20C
   Sends the value periodically over the radio in an LLAP message
   Thermistor NTCLE100E3103JB0; 10kOhm at 25C or 298.15K, Beta value 3977K
   Connections:
      Thermistor connected between 5V and Analog 0 (A0)
      10kOhm resistor connected between Analog 0 and ground
*/

#include <math.h>
#define deviceID1 'X'     // first character of device identifier  
#define deviceID2 'X'     // second character of device identifier
String hdr = "";          // message header

void setup()
{
  pinMode(13, OUTPUT);    // initialize pin 13 as digital output (LED)
  pinMode(8, OUTPUT);     // initialize pin 8 to control the radio
  digitalWrite(8, HIGH);  // select the radio
  Serial.begin(115200);     // start the serial port at 115200 baud (correct for XinoRF and RFu, if using XRF + Arduino you might need 9600)
  hdr = hdr + "a" + deviceID1 + deviceID2;         // message header
  Serial.print(hdr + "STARTED");// transmit started packet
}

float Thermistor(int ADCvalue)
{
  // calculate the temperature from an ADC value
  float T;                      // temperature
  int Beta = 3977;              // beta value for the thermistor
  float Rtemp = 25.0 + 273.15;  // reference temperature (25C)
  float Rresi = 90.0;         // reference resistance at reference temperature - adjust to calibrate
  float Rtherm = (1024.0/ADCvalue - 1)*10000;  // value of the resistance of the thermistor
  T = Rtemp*Beta/(Beta+Rtemp*(log(Rtherm/Rresi))); 
             // see http://en.wikipedia.org/wiki/Thermistor for an explanation of the formula
  T = T - 273.15;               // convert from Kelvin to Celsius
  return T;
}

void loop()
{
  static char tempbuffer[4];        // to store the ASCII chars for temp
  double temp = Thermistor(analogRead(0));  // read sensor and convert to temperature
  if (temp < 10) {
    digitalWrite(13, HIGH);         // turn LED ON
  }
  else digitalWrite(13, LOW);
  dtostrf(temp,4,2,tempbuffer);     // convert double to string
  Serial.println(hdr + "TMPA" + tempbuffer); // send message
  delay(2000);
}

and when i open the serial windows and RF com port i get a good output like so

...TMPA20.86
...TMPA20.86
...TMPA20.86
...TMPA20.86
...TMPA20.86
...TMPA20.86
...TMPA20.86
...TMPA20.86

but once i unplug it from the usb then plug it back into either the same USB socket or a External battery i get a jumbled mess of just random letters and numbers
i have tried reloading and the same

xinoRF ?
It seems to be an Uno with a XBee compatible RF chip:
http://shop.ciseco.co.uk/xinorf-100-arduino-uno-r3-based-dev-board-with-radio-transciever/

Your sketch is a mix of everything, that results into confusing code. Here are a few:

  • There is no ‘double’ in the Arduino Uno. The compiler replaces it with ‘float’.
  • A part of the sketch uses the String object, another part avoid it and uses dtostrf(). The Arduino Uno is a microcontroller for normal tasks. If you can avoid the String object, you have more ram memory for arrays and buffers. Many of use don’t use String objects for an Arduino Uno, but they can be used for ARM processors like the Arduino Due.
  • The variable ‘tempbuffer’ is static. Why ?
  • You try to fill 6 characters into ‘tempbuffer’ and it’s size is only 4. Please make the size 10 bytes.
  • This code scares me a lot: float Rtherm = ( 1024.0 / ADCvalue - 1) * 10000 ;.
    If you want to calculate it with floating point numbers, please convert everything to float before doing a calculation. It think the compiler will do it right, but it is better to be sure.
  • Compare a float with an integer: if ( temp < 10) {.
    I prefer to compare a float with a float, like this: if ( temp < 10.0 ) {

i got the code from the pople i got the xino RF from
http://openmicros.org/index.php/articles/88-ciseco-product-documentation/235-xinorf-learning-the-basics

so im not sure i just needed a quick temp readout i could receive from my computer via RF
as i needed it in the fridge as we thought it was losing temp with the door closed

so i did a search and found this

i happened to have a Thermistor and the XIno so i thrown it together

I see. Well, that code is not very good. It’s bad.
Could you try to change “tempbuffer [ 4 ] ;” into “tempbuffer [ 10 ] ;”.