Temperature monitoring system using XBee, Arduino and Tmp36

82 views
Skip to first unread message

Ammu Jose

unread,
Dec 4, 2014, 11:11:24 AM12/4/14
to north-ea...@googlegroups.com
Hi,
 
I am working on Arduino and Xbee to make a temperature monitoring system using Tmp36. I programmed my arduino to receive temperature data from the tmp36. My problem is that the temperature readings I get are all in negative. I tried changing my program several times, but there was no change in the sign. Would that be the problem of the temperature sensor?
 
Thank you.

David Pye

unread,
Dec 4, 2014, 11:13:40 AM12/4/14
to north-ea...@googlegroups.com
Hi,

Possibly, but difficult to be sure without seeing the circuit, and seeing the code...!

David

--
You received this message because you are subscribed to the Google Groups "North East Makers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to north-east-mak...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Davies

unread,
Dec 4, 2014, 11:16:01 AM12/4/14
to north-ea...@googlegroups.com
If the temperature is correct with a comparison to another thermometer/temperature sensor, you could just pass it through an abs() mathematical function to make the negative figure a positive one.

Ultimately though, as David said, it is impossible to give suitable assistance without seeing the code and the circuit.

John McKenna

unread,
Dec 4, 2014, 11:29:14 AM12/4/14
to Makers
As others have said, a lot depends on the circuit and the code.
 
If the TMP36 is in one of the packages that has a /SHUTDOWN pin, do you have it connected to +Vs?
 
Have you measured the voltage on the output of the TMP36?  If it's 25 degrees in the room, you should expect 0.75V.  If you stick your finger on it to warm it up, the voltage should increase.  If there's no output, then it's either a dead sensor or you've got it connected wrong.
 
If the output looks like it should, do you have it connected to the right input on the Arduino?  It will have to be one of the analogue inputs.  Does the software know it's connected to this pin?
 
What sort of readings do you get?  Do they change if you heat or cool the sensor?
 

Date: Thu, 4 Dec 2014 08:11:24 -0800
From: ammu...@gmail.com
To: north-ea...@googlegroups.com
Subject: [Makers] Temperature monitoring system using XBee, Arduino and Tmp36


Hi,
 
I am working on Arduino and Xbee to make a temperature monitoring system using Tmp36. I programmed my arduino to receive temperature data from the tmp36. My problem is that the temperature readings I get are all in negative. I tried changing my program several times, but there was no change in the sign. Would that be the problem of the temperature sensor?
 
Thank you.

Ammu Jose

unread,
Dec 4, 2014, 11:39:52 AM12/4/14
to north-ea...@googlegroups.com
Thank you for the suggestions.
The code I used is:
char tmpstring[10];
int tmpPin = 3;
void setup()
{
Serial.begin(9600);
delay(2000);
}
void loop()
{
int tmpread = analogRead(tmpPin);
float tmpVolt = float(tmpread)/1024;
float tmpC = (100 * tmpVolt) - 50;
dtostrf(tmpC, 8, 2, tmpstring);
Serial.print("temperature in celsius: ");
Serial.println(tmpstring);
delay (2000);

Ammu Jose

unread,
Dec 4, 2014, 11:45:14 AM12/4/14
to north-ea...@googlegroups.com
Actually I was following the instructions on adafruit website. I connected the tmp36 with my arduino as suggested on the website. I tried cooling and heating up the tmp36 and it gave me different readings accordingly. If there wasn't that negative sign, then the readings are correct.

David Pye

unread,
Dec 4, 2014, 11:45:37 AM12/4/14
to north-ea...@googlegroups.com
My first simplification of that would be just this:

Serial.print(analogRead(tmpPin);

and junk the rest.  And see if that gives you a value that changes in response to gently warming the sensor with your fingers.   If so, then you know the code/maths/casting stuff is the problem and not the sensor.

In setup() you should also have a pinMode(3, INPUT); in my opinion, though there are debates as to whether this is necessary.


David

Ammu Jose

unread,
Dec 4, 2014, 11:48:33 AM12/4/14
to north-ea...@googlegroups.com
Thank you David. I will try your suggestion and let you know.

David Pye

unread,
Dec 4, 2014, 11:49:51 AM12/4/14
to north-ea...@googlegroups.com
Oops  - clearly I am missing a )

It should have been

int tmpPin = 3;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(analogRead(tmpPin));
delay (2000);
}

That's kind of the most basic simplification of that code, and if it gives you things like :

347
460
500

etc, you know that your wiring/sensor etc is good.

David

Ammu Jose

unread,
Dec 4, 2014, 11:53:35 AM12/4/14
to north-ea...@googlegroups.com
Ok. I will try that one. Thank you.

Greg Fenton

unread,
Dec 4, 2014, 11:54:48 AM12/4/14
to north-ea...@googlegroups.com
TMP36 gives an output from -40 to 125 centigrade.

0v is -40, 2v is 125.

We can use the map() function to get the correct voltage:
float temp = map(0, 2048, -40, 125);

Try that and let us know.

Regards

Greg

Greg Fenton

unread,
Dec 4, 2014, 11:57:18 AM12/4/14
to north-ea...@googlegroups.com
Silly me, I forgot to add the code for the actual value :P

int v = analogRead(tmpPin);
int temp = map(v, , 2048, -40, 125);

Greg

Greg Fenton

unread,
Dec 4, 2014, 11:57:59 AM12/4/14
to north-ea...@googlegroups.com
Gaah!

int v = analogRead(tmpPin);
int temp = map(v, 0, 2048, -40, 125);

Stupid keyboard eating zeros

John McKenna

unread,
Dec 4, 2014, 12:06:06 PM12/4/14
to Makers
If you're not changing the ADC's reference voltage with analogReference(), it'll use either 5V or 3.3V depending on exactly which Arduino you've got.  That's far above the range the sensor needs, but never mind.
 
Let's say it's 25 degrees, assume the reference is 5V, and walk through it.  25 degrees will give a voltage of 0.75V, which is 0.15 of the full 5V range, so analogRead will return 153.  Dividing that by 1024 gives 0.149.  Multiplying by 100 and subtracting 50 gives -35.  This is clearly wrong, so there is definitely a problem in the code.
 
I think your mistake is assuming that tmpVolt is the voltage in volts.  It isn't: it's the proportion of the reference voltage.  To get the actual voltage, you need to multiply it by 5 (if that's what the reference is).  After that, it should work.
 
Once it's working, it's worth looking at a lower reference voltage.  5V/1024 = 4.88mV, so you're only getting about half a degree per step (with any non-linearity or noise meaning actual performance is less).  If you can get 1.25V onto the AREF pin, call AnalogReference(EXTERNAL), and multiply tmpVolt by 1.25 instead of 5, you'll get just over 0.1 degree per step, and still be able to measure temperatures up to 75 degrees.
 

Date: Thu, 4 Dec 2014 08:39:52 -0800
From: ammu...@gmail.com
To: north-ea...@googlegroups.com
Subject: Re: [Makers] Temperature monitoring system using XBee, Arduino and Tmp36

Greg Fenton

unread,
Dec 4, 2014, 12:10:22 PM12/4/14
to north-ea...@googlegroups.com
And to top it all I just realised that I have put 2048 when I meant
410 (40% of 1024 = 409.6). Please change the code accordingly.
..must..not..code..when..tired..

Ammu Jose

unread,
Dec 4, 2014, 12:40:38 PM12/4/14
to north-ea...@googlegroups.com
Thank you all. I will change my code and try again and let you know.

You received this message because you are subscribed to a topic in the Google Groups "North East Makers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/north-east-makers/6IY-nQw78PU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to north-east-mak...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Ammu Jose.

Ammu Jose

unread,
Dec 4, 2014, 1:42:47 PM12/4/14
to north-ea...@googlegroups.com
Hi David,
I tried what you said and I got the readings as:

329
312
310...

--
You received this message because you are subscribed to a topic in the Google Groups "North East Makers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/north-east-makers/6IY-nQw78PU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to north-east-mak...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Ammu Jose.

Ammu Jose

unread,
Dec 4, 2014, 1:46:43 PM12/4/14
to north-ea...@googlegroups.com
Hi Greg,
When I tried your code, I got
-15
-16...

You received this message because you are subscribed to a topic in the Google Groups "North East Makers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/north-east-makers/6IY-nQw78PU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to north-east-mak...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Ammu Jose.

Ammu Jose

unread,
Dec 4, 2014, 1:52:34 PM12/4/14
to north-ea...@googlegroups.com
Hi John,
When I connect the tmp36 to the 5V pin and the ground on the arduino, my arduino stops working. So, I am using the 3.3V pin. What may be the reason for this?
Thank you.

On 4 December 2014 at 17:06, John McKenna <djo...@hotmail.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "North East Makers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/north-east-makers/6IY-nQw78PU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to north-east-mak...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Ammu Jose.

David Pye

unread,
Dec 4, 2014, 1:52:54 PM12/4/14
to north-ea...@googlegroups.com
Hi Ammu,

OK, so you are getting sensible readings from the sensor.  Therefore, you need to have a look at what the code that is 'converting' that value into 'C, because the logic is faulty.

As the others said, that number 300 and something isn't volts, it's a ratio of voltage (probably between 0 and 5v, where 0 is 0v, and 255 is 5v).

So, work through what your code is doing and figure out what to do to get 'C.  You might want to have a look at the data sheet for the TMP sensor.


David

Ammu Jose

unread,
Dec 4, 2014, 1:54:38 PM12/4/14
to north-ea...@googlegroups.com
Thank you David. I will look on to that.

David Pye

unread,
Dec 4, 2014, 2:00:17 PM12/4/14
to north-ea...@googlegroups.com
5V should be fine as a input.


Check it's the right way round ;-)

If its shorting, that will stop the arduino.

Ammu Jose

unread,
Dec 4, 2014, 2:07:55 PM12/4/14
to north-ea...@googlegroups.com
Thank you David. With mine, the 5V is not working. 3.3V is working fine. Would that be a problem?

David Pye

unread,
Dec 4, 2014, 2:16:44 PM12/4/14
to north-ea...@googlegroups.com
It's a problem in that something weird is happening, and you haven't figured out why yet!

This *should* work with 5v, so if it isnt' there is something strange happening that needs to be understood.

When you say the arduino doesn't work, what exactly happens?  Does it disappear off USB, and can't be programmed until you remove the TMP?  If so, that sounds like it is shorting out something and pulling the 5v rail low.

If the arduino can be programmed, but your code doesn't say anything over serial, that's different.

David

David Pye

unread,
Dec 4, 2014, 2:17:47 PM12/4/14
to north-ea...@googlegroups.com
Another suggestion would be to pop along to the space on a Wednesday or similar open evening, and people can have a look with you.

David

Ammu Jose

unread,
Dec 4, 2014, 2:30:08 PM12/4/14
to north-ea...@googlegroups.com
Thank you David. As you said, my arduino is shorting out and disappears off the USB and can't be programmed until I remove the connection from either ground or the 5V pin.

David Pye

unread,
Dec 4, 2014, 2:33:42 PM12/4/14
to north-ea...@googlegroups.com
Intriguing.

Then it sounds like your TMP36 is perhaps faulty?  Is it definitely connected the right way round?  Do you have another you could try?

David

Ammu Jose

unread,
Dec 4, 2014, 2:37:13 PM12/4/14
to north-ea...@googlegroups.com
Yes I connected it according to the adafruit website. I have five of them and it is the same with all of them.

David Pye

unread,
Dec 4, 2014, 2:38:55 PM12/4/14
to north-ea...@googlegroups.com
Can you tell us the markings on the sensor itself? As well as TMP36 it may have other numbers.

I'm running out of ideas a bit here.


Ammu Jose

unread,
Dec 4, 2014, 2:43:42 PM12/4/14
to north-ea...@googlegroups.com
It shows TMP36GZ 045993156

Ammu Jose

unread,
Dec 4, 2014, 2:45:32 PM12/4/14
to north-ea...@googlegroups.com
Even if I take out the tmp36 from the arduino, it still gives me readings. Does that mean my arduino is not responding to the tmp36?
--
Ammu Jose.

David Pye

unread,
Dec 4, 2014, 2:50:39 PM12/4/14
to north-ea...@googlegroups.com
Quite possibly ;-)

There will be a value on a floating pin anyway though, so it doesn't necessarily mean anything.

If you forget the arduino, and just power the TMP36 from 5v and GND, and measure the voltage on the output pin with a multimeter, what do you get?

David

Ammu Jose

unread,
Dec 4, 2014, 2:52:46 PM12/4/14
to north-ea...@googlegroups.com
I haven't tried that yet. I don't have a multimeter with me now. Probably, I can check it tomorrow.

David Pye

unread,
Dec 4, 2014, 2:54:41 PM12/4/14
to north-ea...@googlegroups.com
I think that's worth a go..

But something odd is going on if you cannot power the temperature sensors from 5v, gnd and read a sensible analog voltage from the centre pin, which changes with body heat.

David

Ammu Jose

unread,
Dec 4, 2014, 2:59:09 PM12/4/14
to north-ea...@googlegroups.com
Ok. I will definitely try that and let you know.

Ammu Jose

unread,
Dec 9, 2014, 11:59:30 AM12/9/14
to north-ea...@googlegroups.com
Hi all
I got my coding right. I changed the sign on tmpC in "dtostrf(tmpC, 8, 2, tmpstring);"  as "-". Then I got the readings right.
Thank you all for the suggestions.
Ammu.
--
Ammu Jose.
Reply all
Reply to author
Forward
0 new messages