Go Down

Topic: Temperature readings (Read 1 time) previous topic - next topic

uink

I'm having a little trouble hooking up my 10k themistor and resistor to my UNO, but I think i got it.  I am trying to sense the ambient temperature.  I am using a code that i used in a LilyPad project, so i know the code works.  However, when i run the code with my UNO, this is what I get:

Temp reading = 1023 - 3.30 volts
279.68 degress C
535.42 degress F

Anyone have any advice?
Thanks

CrossRoads

Assuming 1023 is the analog reading you are getting from the A/D converter, looks like it is just reading 5V, and not doing any resister-divider kind of function.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

uink

How do i fix that?
I'm totally new to arduino!

liudr

Since you are new, you need to provide your code and picture of your connections. That's typically needed for an answer. We don't have crystal balls.

AWOL

Maybe it is just a bit warmer than usual.

Maybe you could post your code and your circuit.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

robtillaart

Please post your code.

think you need to add conditional code, something like

#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)  // the 5 volt devices
 code for 5 Volt devices
#else
 code for 3.3Volt devices
#endif


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

uink

#6
Jun 20, 2011, 03:53 pm Last Edit: Jun 20, 2011, 04:08 pm by ABIA Reason: 1
OK, I need to start thinking!!
Sorry, i can't take a picture.  But here are my connections

I have my thermistor in gnd
i have my resistor in a different gnd
I have both of them in analog in (A0)

Here is my code:

Code: [Select]
/* Sensor test sketch
 for more information see http://www.ladyada.net/make/logshield/lighttemp.html
 */

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!




//TMP36 Pin Variables
int tempPin = 1;        //the analog pin the TMP36's Vout (sense) pin is connected to
                       //the resolution is 10 mV / degree centigrade with a
                       //500 mV offset to allow for negative temperatures
int tempReading;        // the analog reading from the sensor

void setup(void) {
 // We'll send debugging information via the Serial monitor
 Serial.begin(9600);  

 // If you want to set the aref to something other than 5v
 analogReference(EXTERNAL);
}


void loop(void) {

 tempReading = analogRead(tempPin);  

 Serial.print("Temp reading = ");
 Serial.print(tempReading);     // the raw analog reading

 // converting that reading to voltage, which is based off the reference voltage
 float voltage = tempReading * aref_voltage;
 voltage /= 1024.0;

 // print out the voltage
 Serial.print(" - ");
 Serial.print(voltage); Serial.println(" volts");

 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                              //to degrees ((volatge - 500mV) times 100)
 Serial.print(temperatureC); Serial.println(" degress C");

 // now convert to Fahrenheight
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degress F");

 delay(1000);
}


Thanks so much!

robtillaart

Please modify your post, select the code and press # button --> looks so much better
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

AWOL

Quote
I have my thermistor in gnd
i have my resistor in a different gnd
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

commanda

There's a good write-up here:
http://www.arduino.cc/playground/ComponentLib/Thermistor2

This is my version, where the thermistor goes to ground and the pad resistor goes to positive.
sensorTempValue is already returned from analog read.

Code: [Select]


float calcTempValue; 

void calcTemperature()
{
  // utilizes the Steinhart-Hart Thermistor Equation
  // sample code from Arduino playground Thermistor2

  // this will have to be tested using resistors to simulate the thermistor
  // using values from CityCell's datasheet. (DONE 2011-05-26 AW)
  // As an example, typical values for a thermistor with a resistance of 3000 ? at room temperature (25 °C = 298.15 K) are:

  //  a = 1.40 \times 10^{-3}

  //  b = 2.37 \times 10^{-4}

  //  c = 9.90 \times 10^{-8}

  // float thermR = 3000;            // nominal value of thermistor
  const float pad = 10000;               // value of pull-up resistor
  const float factorA = 1.4E-03;
  const float factorB = 2.37E-04;
  const float factorC = 9.90E-08;

  long resistance;
  float Temp;                      // a local temporary variable


  resistance = sensorTempValue * pad / (1024 - sensorTempValue);   // changed from sample code as our thermistor
  // goes to ground (NOT Vcc)                                                 
  // we use 1024  so an open cct thermister won't throw a divide-by-zero error                                                   

  Temp = log(resistance);
  Temp = 1 / (factorA + (factorB * Temp) + (factorC * Temp * Temp * Temp));
  calcTempValue = Temp - 273.15;            // convert Kelvin to Celsius


}  // end calcTemperature()



Amanda

liudr

Here's my tutorial with real pictures:

http://liudr.wordpress.com/2011/02/10/measure-temperature/

The circuit shows that your "other ground" is supposed to be 5V.



The R_unknown is the thermistor and R_known is the 10Kohm resistor.

I think you used the wrong code. The code is for a TMP36 sensor, not a thermistor.

liudr

Here is the loop(). You will need Serial.begin(9600); in setup()
Code: [Select]

  float resistance, voltage, r_fixed, T0, T, R0,B;
  T0 = 298.15;//initial temperature for calibration
  R0 = 10000;//initial resistance for calibration
  r_fixed = 10972;//known resistance
  B = 4050;//B for normalization
  Serial.println("Temperature");

  while(1)
  {
    voltage = analogRead(sensor_a)*5.0/1024;// Renormalizing from 0 to 5 volts.
    resistance = voltage*r_fixed/(5.00-voltage);//find unknown resistance
    T = 1/(log(resistance/r_fixed)/B+1/T0)-273.14;//find temperature from unknown ressistance
    Serial.println(T);
    delay(500);
  }



I have reconnected my thermistor according to liudr's blog.  However, no code i try is uploading, even codes that were working before!!


What do you mean by not uploading? What error message?

uink

Okay, it is finally uploading again!! Here is the code i uploaded.  However, it still gives me insanely high readings.  What can i do???
BTW, i am on 9600 baud
Code: [Select]
/* Sensor test sketch
 
 */

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!




//TMP36 Pin Variables
int tempPin = 1;        //the analog pin the TMP36's Vout (sense) pin is connected to
                       //the resolution is 10 mV / degree centigrade with a
                       //500 mV offset to allow for negative temperatures
int tempReading;        // the analog reading from the sensor

void setup(void) {
 // We'll send debugging information via the Serial monitor
 Serial.begin(9600);  

 // If you want to set the aref to something other than 5v
 analogReference(EXTERNAL);
}


void loop(void) {

 tempReading = analogRead(tempPin);  

 Serial.print("Temp reading = ");
 Serial.print(tempReading);     // the raw analog reading

 // converting that reading to voltage, which is based off the reference voltage
 float voltage = tempReading * aref_voltage;
 voltage /= 1024.0;

 // print out the voltage
 Serial.print(" - ");
 Serial.print(voltage); Serial.println(" volts");

 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                              //to degrees ((volatge - 500mV) times 100)
 Serial.print(temperatureC); Serial.println(" degress C");

 // now convert to Fahrenheight
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degress F");

 delay(1000);
}



liudr

I don't think you read my replies very carefully. You are using the wrong code so re-read my replies and upload the right code.

uink

#14
Jun 20, 2011, 07:31 pm Last Edit: Jun 22, 2011, 05:20 pm by ABIA Reason: 1
I got it working! I needed a different code and resistor.  I posted those details in Sensors under Arudino thermistor.
Thanks to all for their help!

Go Up