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

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

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

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 :wink: So, what’s going on?

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

2 Likes

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

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 about analog readings.

1 Like

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

Yeah we can’t upload pics directly to the forum either. 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().

1 Like

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 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.

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.

4 Likes

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!

2 Likes

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.

1 Like

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

Yup, in another thread we’ve been finding the A0 cap to GND is the solution as well :wink:

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.

@Heri, sounds like you are good at troubleshooting :slight_smile: 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 :wink:

945 by my sums is 19.2 degrees

(my current results are 948 = 19.3)

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

@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.

@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.

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.

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.

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

@Pharmboyz try these changes :wink:

1 Like