# "Measuring the temperature"-sample not getting to work correctly

**URL:** <https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029>\
**Category:** Troubleshooting\
**Created:** [December 27, 2013, 3:48pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029 "2013-12-27T15:48:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peerke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peerke/32/20989_2.png) [@Peerke](https://community.particle.io/u/Peerke)\
**Post date:** [December 27, 2013, 3:48pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/1 "2013-12-27T15:48:59Z")

</div>

First of all, I’m not really a expert on electronics, so bear with me 😉

I bought a Spark Core Maker kit (will all kind of stuff in it) and I started with the “Measuring the temperature”-sample on [http://docs.spark.io/#/examples](http://docs.spark.io/#/examples)

I have connected everything the same way as on the photo and flashed my core with the example program.

When I retrieve the values from the input pin I get values around 1300. When I convert this to a voltage I get 1.04v. Convert this into a temperature I get 55 degrees Celsius. I’m very sure, it’s not that hot in here 😉 So, what’s going on?

Can somebody tell me what I’m doing wrong? I followed the example to the letter.

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [December 27, 2013, 3:53pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/2 "2013-12-27T15:53:10Z")

</div>

Might be a wiring issue… Can you share a picture of your wiring setup? Make sure the temp sensor is in the correct way.

---

<div class="post-metadata">

**Author:** ![DougC](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dougc/32/20998_2.png) [@DougC](https://community.particle.io/u/DougC)\
**Post date:** [December 27, 2013, 6:07pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/3 "2013-12-27T18:07:09Z")

</div>

This sounds similar to what I am seeing. There’s a discussion in this thread [https://community.spark.io/t/odd-analog-readings/906/7](https://community.spark.io/t/odd-analog-readings/906/7) about analog readings.

---

<div class="post-metadata">

**Author:** ![Peerke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peerke/32/20989_2.png) [@Peerke](https://community.particle.io/u/Peerke)\
**Post date:** [December 27, 2013, 11:32pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/4 "2013-12-27T23:32:08Z")

</div>

I can’t upload pictures on the forum yet. But I put the picture in my dropbox: [https://dl.dropboxusercontent.com/u/47148896/2013-12-28%2000.28.50.jpg](https://dl.dropboxusercontent.com/u/47148896/2013-12-28%2000.28.50.jpg)

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [December 28, 2013, 12:22am UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/5 "2013-12-28T00:22:34Z")

</div>

Yeah we can’t upload pics directly to the forum either. [http://imgur.com](http://imgur.com) seems to work the best for me.

Your wiring looks correct. You might try to replace the jumpers with new ones, sometimes those jumpers can have cold solder joint where the wire connects to the pin.

If you had a voltmeter I would want to know if your A0 pin measures 1.04V with respect to GND. But I’m guessing you don’t.

Does the kit have two 1k ohm resistors? (brown black red gold). If so, remove the Temp sensor, and put one resistor between A0 and GND, and the other between A0 and 3.3\*. This will setup a fairly approximate ~1.65V on A0, which we can then compare to the readings from the analogRead().

---

<div class="post-metadata">

**Author:** ![Elijah](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/elijah/32/88_2.png) [@Elijah](https://community.particle.io/u/Elijah)\
**Post date:** [December 28, 2013, 3:25am UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/7 "2013-12-28T03:25:16Z")

</div>

I hope you’re able to get it working; looking at the example I am not sure how the provided code will convert to celsius from -40C to 125C. Here’s the formula given:

`voltage = (sensor_readout * 3.3)/4095 temperature = (voltage - 0.5) * 100`

Looking at the [datasheet](http://www.analog.com/static/imported-files/data_sheets/TMP35_36_37.pdf) it looks like the max. sensor reading with this formula would correspond to a temperature of ~280C. The sensor datasheet gives a response of 10mV/celsius. With the given formula 10mV corresponds to a sensor readout change of 124, but if the sensor is rated to work linearly from -40C to 125C then those 165 degrees of change correspond to sensor readout from 0 to 20640.

This is one of those cases where I really wish I knew what I was missing, and again I hope you’re able to figure it out soon.

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [December 28, 2013, 5:23am UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/8 "2013-12-28T05:23:16Z")

</div>

I'm not sure how you got those numbers but hopefully this helps clear some things up...

The TMP36 outputs 0.75V at 25°C, with an output scale factor of 10mV/°C.

Therefore it will output 0.10V at -40°C and 1.75V at 125°C.

With a 12-bit A/D this will give an approximate reading of:  
0.10V / 3.3V x 4095 = 124 decimal at -40°C  
1.75V / 3.3V x 4095 = 2172 decimal at 125°C

Some problems may be arising from not having a decoupling capacitor across the supply pins of the temperature sensor. Read this note from the datasheet:

> Note the 0.1 μF bypass capacitor on the input. This capacitor should be a ceramic type, have very short leads (surface-mount is preferable), and be located as close as possible in physical proximity to the temperature sensor supply pin. Because these temperature sensors operate on very little supply current and may be exposed to very hostile electrical environments, it is important to minimize the effects of radio frequency interference (RFI) on these devices. The effect of RFI on these temperature sensors specifically and on analog ICs in general is **manifested as abnormal dc shifts in the output voltage** due to the rectification of the high frequency ambient noise by the IC. When the devices are operated in the presence of high frequency radiated or conducted noise, a large value tantalum capacitor (±2.2 μF) placed across the 0.1 μF ceramic capacitor may offer additional noise immunity.

We are basically sticking the temp sensor right next to the Wifi chip antenna, without a decoupling capacitor...

**Anyone having problems with readings should try to put a 0.1uF (or larger) ceramic cap directly between pins 1 and 3 of the TMP36.**

---

<div class="post-metadata">

**Author:** ![Elijah](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/elijah/32/88_2.png) [@Elijah](https://community.particle.io/u/Elijah)\
**Post date:** [December 28, 2013, 7:01am UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/9 "2013-12-28T07:01:23Z")

</div>

Thanks, BDub! I was blithely assuming the readout at the maximum rated temperature would be converted to the maximum decimal, 4095.

It sounds like this could very well be the fix!

---

<div class="post-metadata">

**Author:** ![Peerke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peerke/32/20989_2.png) [@Peerke](https://community.particle.io/u/Peerke)\
**Post date:** [January 2, 2014, 12:29pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/11 "2014-01-02T12:29:10Z")

</div>

Thanks for all the responses, but nothing in this topic seemed to work. I finally got it to work by connecting 0.01 μF ceramic cap from the ground to the A0 pin.  
Maybe this will help somebody else that has the same problem.

---

<div class="post-metadata">

**Author:** ![Sauli](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@Sauli](https://community.particle.io/u/Sauli)\
**Post date:** [January 2, 2014, 8:49pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/12 "2014-01-02T20:49:01Z")

</div>

Thanks. Adding the ceramic cap from the ground to the A0 pin did help me to get the example working.

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 2, 2014, 9:07pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/13 "2014-01-02T21:07:00Z")

</div>

Yup, in [**another thread**](https://community.spark.io/t/odd-analog-readings/906/31) we’ve been finding the A0 cap to GND is the solution as well 😉

---

<div class="post-metadata">

**Author:** ![Heri](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Heri](https://community.particle.io/u/Heri)\
**Post date:** [January 15, 2014, 6:30pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/14 "2014-01-15T18:30:39Z")

</div>

Is there another possible cause for such an error?

I consistently get values which are 4-5 degrees higher than expected, for example a reading of 945, which corresponds to 26° C, but another thermometer in the room says about 21.x° C. I even put the Spark board in my fridge where the values were also 4-5 degrees higher than the fridge thermometer.  
I tried to put “caps everywhere”, 0.01 μF between A0 and ground, 0.1uF between pins 1 and 3 of the TMP36, and both, without any impact on the values.  
A 10k / 10k resistor divider in place of the TMP36 leads to values around 2055, which is basically as expected.

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 15, 2014, 8:54pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/15 "2014-01-15T20:54:43Z")

</div>

@Heri, sounds like you are good at troubleshooting 🙂 If you are getting a consistent 4-5 degree higher than expected offset across your entire usable temp range for the TMP36, I would suggest subtracting 50 to 62 in decimal from your ADC readings to normalize the offset. It’s not uncommon to have to calibrate the offset of a temperature sensor. This is a good problem to have, because it’s easily solved with a known good reference temperature 😉

---

<div class="post-metadata">

**Author:** ![defsdoor](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@defsdoor](https://community.particle.io/u/defsdoor)\
**Post date:** [January 15, 2014, 10:51pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/16 "2014-01-15T22:51:04Z")

</div>

945 by my sums is 19.2 degrees

(my current results are 948 = 19.3)

```
( ( ( (948 * 3.0) / 4095 ) - 0.5) * 100 )

```

---

<div class="post-metadata">

**Author:** ![Heri](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Heri](https://community.particle.io/u/Heri)\
**Post date:** [January 15, 2014, 11:33pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/17 "2014-01-15T23:33:17Z")

</div>

@BDub, I thought based on the TMP36 datasheet there is no external calibration required, and my measured deviation was beyond the accuracy listed in the datasheet. Am I understanding something wrong there?

@defsdoor, the voltage factor should be 3.3 instead of 3.0.

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 15, 2014, 11:57pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/18 "2014-01-15T23:57:53Z")

</div>

@Heri yeah, you’re right… I was hoping to sneak one past you… haha. Really though… is it a consistent offset? Can you show a picture of your wiring?

When I get the TMP36 that I ordered…like 2 weeks ago! I’ll have my hands on this problem and offer some better solutions.

---

<div class="post-metadata">

**Author:** ![Pharmboyz](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Pharmboyz](https://community.particle.io/u/Pharmboyz)\
**Post date:** [January 16, 2014, 4:50am UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/19 "2014-01-16T04:50:24Z")

</div>

> [@Peerke](#):
>
> 0.01 μF ceramic cap

Can someone please put up a photo of what putting the ceramic cap from GND to AO looks like? Got my training wheels on and some of this is hard to visualise. So a photo or fritzing diagram of the final config would be great! Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Pharmboyz](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Pharmboyz](https://community.particle.io/u/Pharmboyz)\
**Post date:** [January 16, 2014, 5:31am UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/20 "2014-01-16T05:31:44Z")

</div>

![](https://sea2.discourse-cdn.com/flex026/uploads/particle/281/9f3354284c4999bb.png)

This is the config I have. 0.01uF cap on pin 1, 3 of the TMP 36. Getting all sorts of queer readings so wondering if I have a faulty TMP 36 as it jumps by 1000 units per 5 secs etc etc.

---

<div class="post-metadata">

**Author:** ![Pharmboyz](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Pharmboyz](https://community.particle.io/u/Pharmboyz)\
**Post date:** [January 16, 2014, 5:33am UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/21 "2014-01-16T05:33:03Z")

</div>

Whoops obviously when I have A0 connected properly. It still jumps around even though I’m stupid.

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 16, 2014, 7:18pm UTC](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029/22 "2014-01-16T19:18:04Z")

</div>

@Pharmboyz try these changes 😉

![](https://sea2.discourse-cdn.com/flex026/uploads/particle/284/3cf5d263cb20422a.jpg)

[Next page](https://community.particle.io/t/measuring-the-temperature-sample-not-getting-to-work-correctly/1029.md?page=2)
