TMP36 reading analog values of around 370~395 [SOLVED]

Hi there,

I’m fairly new to the Spark Core, so please bear with me :smile:

I’m trying to get temperature readings by using a TMP36 temperature sensor, which I’ve managed to do with an Arduino. However with the Spark Core I’m getting analog readings of about 370~395 which isn’t converting to temperatures that make sense. Others who have tried this seem to mention much higher analog readings than this.

I’m using the example code under the Spark.variable() section here - http://docs.spark.io/firmware/.

What could I be doing wrong? Any help would be much appreciated!

Cheers,
Annie

2 Likes

Hi @codefrenzy

Do you have it hooked up up like this:

The blue capacitor is optional but does help with stability.

3 Likes

The image @bko posted is from the Measuring the Temperature section in the Annotated Examples part of the docs. There’s some explanation there (also pasted below) about the capacitor and why the sensor is so far away on the board:

Notice how we are powering the sensor from 3.3V* pin instead of the regular 3.3V. This is because the 3.3V* pin gives out a (LC) clean filtered voltage, ideal for analog applications like these. If the readings you get are noisy or inconsistent, add a 0.01uF (10nF) ceramic capacitor between the analog input pin (in this case,A7) and GND as shown in the set up. Ideally, the sensor should be placed away from the Core so that the heat dissipated by the Core does not affect the temperature readings.```
2 Likes

Thanks for the quick responses!

Hmm, no, I didn’t have it like that. I had a couple of things connected differently:

  1. I wasn’t connected to the 3.3V* pin. I had it connected to the VIn which I now see I really shouldn’t have been… https://community.spark.io/t/using-the-vin-as-a-5v-source/1040.
  2. I didn’t have a capacitor although the closest one I have is from my Arduino kit and is 100pF which I think is too small?

Now that I have it hooked up as in your schematic @bko, I am getting much better readings - 923~930 which convert to about 24.38 C. That does seem a bit high though… the thermostat in my apartment tells me it’s currently 22 C. I’ve read that the TMP36 is accurate to about ±2 C so could this be more or less ok? Or perhaps the 3.3V* pin isn’t giving off 3.3V?

Thanks again :smile:

1 Like

One other effect is that the Spark core runs a bit warm, like just slightly warm to the touch. This is enough to heat up the breadboard over time and raise the temp of the sensor a few degrees from the air temp. If you can get the TMP36 physically away from the Spark with longer wires solder on or another breadboard that is not touching, the readings will be more accurate.

They are usually very sensitive – if you blow on it or put your finger to it, it will shoot right up.

1 Like

I’m having the exact same problem, TMP36 is returning values between 350 and 400 which would represent very low temperatures. I have wired it exactly as the annotated example suggests with the exception of the ceramic capacitor (just because I didn’t have one at home).
Would it be just because of the lack of the capacitor? I am using the LC voltage…

EDIT: I have now added the 10nF capacitor and the values are within the range they should be, so that was definitely the issue. Use the capacitor! Thanks @psb777 for the reply.

Use the capacitor - for me this wasn’t just stability, it made the readings fall into the correct range too.

1 Like

Yeah, the capacitor is not optional for me either in order to get the correct readings. Use it. (Otherwise, the values are way low and show -22°C.)

The TMP36 needs a resistor between VOUT and GND, or its readings will be almost random.

1 Like

Can anyone provide me with the code they are using for the Temperature sensor

Cheers

Try this (it’s a quick “port” of adafruit code - since I can’t find the Particle version right now)

/* 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 = A7;        //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() 
{
  // We'll send debugging information via the Serial monitor
  Serial.begin(115200);   
}
 
void loop() 
{
  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 /= 4095.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(" degrees C");
 
  // now convert to Fahrenheight
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  Serial.print(temperatureF); Serial.println(" degrees F");
 
  delay(1000);
}

(no warranty - not tested - but builds OK) :wink:

1 Like

Here are the two functions currently running in my photon:

double getCentigrade()
{
	// http://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf
	short mV = readMilliVolts(TMP36_PIN);
	return (mV / 1000.0 - 0.5) * 100.0;
}

short readMilliVolts(int pin)
{
	return map(analogRead(pin), 0, 4095, 0, VCC);
}

VCC is a #DEFINE constant of the measured millivolts of the 3.3V pin on the photon

Old topic I know. Correct me if I am wrong to question things, but is that fritzing thing right? The capacitor is between Vout and GND?
The TMP36 data sheet recommends a 0.1uf Ceramic, between +Vs and GND.
Also, they recommend the capacitor is placed as close to the TMP36 as possible.
Steve

(edited: I typed Vs instead of Vout)

Hi @steve1001

The capacitor recommended in the TMP36 datasheet is a bypass cap, used to remove noise from the power supply. It is a good idea too.

But the capacitor here is from the analog input to ground. The Core and Photon analog to digital converters use a fairly low-impedance input with internal switch capacitors, so you can use the external capacitor shown here, or add an external op-amp to make the TMP36 work correctly.

The best way to think about it is that the TMP36 cannot drive the inputs on a Core or Photon without some help, either an averaging capacitor or an op-amp.

1 Like

Hi bko

That does make sense now you explain it.

Thanks for that.

Steve