Temperature sensor reading

Hello.

I'm fairly new on the arduino subject or electronics overall so I would really need help on this one.
I have a temp sensor (PT100 with 2 wires). In order to read the value I would do the following:

One wire goes to ground
second one goes through a resistor to 5v and A0(analog_input).

right?

I used 220ohm resistor. If I get it right now, arduino reads voltage on it's analog pins?

When I look at PT100 datasheet or use this page for an example: http://crivens.dyndns.org/project_pages/electronics/pt100.html
I can say that resistance for 100degrees is 138.500005. so:
Vout=Vin(R2/R1+R2) = 2.78
If I'm right so far then how can I get that reading back into degrees?

I may be completely off with my physics and math so any kind of additional explanation is welcome :slight_smile:

The code I used to print it

int tempval_pin = A0;
int tempval = 0;

void setup () {
Serial.begin(9600);
}

void loop () {
tempval = analogRead(tempval_pin);
templimit = analogRead(templimit_pin);
Serial.println(tempval);
}

the values I get with these are around 378 or so. It doesn't make any sense at the moment. I'm probably doing something very wrong :cold_sweat:
would changing the resistor to 10kohm would change it? or should I use float instead of int?

Take the Arduino out of the circuit. Use an ohm meter on the sensor. Is it working as expected?

change

  tempval = analogRead(tempval_pin);
  templimit = analogRead(templimit_pin);

TO:

  tempval = analogRead(A0);

yes it's working as it should.
and I can see I have accidentally pasted a wrong bit of code. Since it's only a part of a longer code I copy-pasted the sensor part.

templimit is something that should not have been there :stuck_out_tongue:

Also wanted to say that I used map function to translate those readings back to degrees. I have a laser temperature gun to check the actual temperature against the value of the sensor which I get in the serial monitor. For an example:

temperature_actual = map (tempval, 362, 381, 90, 225);

as you can see, the value changes 19 units as degrees changes 135 units. that's not very accurate

using a resistor in series with the temp sensor I should get a voltage divider.

whether I use 220ohm, 1k ohm or 10k ohm resistor, the values always change very little.

220 1000 10000
100 3,068340307 4,391743522 4,93169601
150 2,915374626 4,320363602 4,922563159
200 2,778900566 4,252279222 4,91359927
250 2,656555655 4,1873592 4,904812308
300 2,546178418 4,125344466 4,896190959

using 220 ohm resistor I only get 1 unit of change over 200 degrees?

Serial monitor only reads integer values so no wonder it doesn't change much...

confusing

Yes, it is still a bit confusing, but if we work through it step by step, I bet we will have success.
First, take the arduino, and voltage divider away from the sensor. Use an ohm meter and record the resistance at 100, 150, 200 and 250. Are the readings about what the web page calculates?

Second, hook the voltage divider back up. Use a small value resistor 100 to 220 ohm. Hook the ground, and 5v up (the sensor should be the resistor that goes to ground, if you want your voltage to go up as heat goes up). Do the same test, but this time measure and record the voltage.

Post those readings please.

I ran into trouble of creating constant temperatures of 100+ so I did a test on 25C and 50C.

these are my readings:

25C 50C
V 0,55 0,58
ohm 110 117

resistance adds up pretty accuratelly with the datasheet.

is this enough?

Yes, that should be enough. The voltages are pretty low. I usually prefer the voltages about half of the supply voltage. If we could get it into the 2 to 3 volt range we would have better resolution.
What value was the second resistor for those tests? Can you get it smaller, pretty close to the resistance of the sensor is best.

Then our next test should be to read the voltage through the analog pin, and display the reading, without any calculations, just the raw readings with the same temp. tests you just did.

yes, i just figured I've used 10k ohm earlier. Now I tried the same thing with 220ohm (that's the smallest I've got) and the results are:

28C 50C
V 1,68 1,74
ohm 111 117

readings from arduino:

50C - 378
28C - 353

code i've used:

int sensorpin = A0;

void setup () {
Serial.begin(9600);
}

void loop () {
int sensorval = analogRead(sensorpin);
Serial.println (sensorval);
delay(250);
}

Now, lets try to map it. Maybe like:

void loop () {
int sensorval = analogRead(sensorpin);
int tempC = map(sensorval, 353, 378, 28, 50)
Serial.println (tempC);
Serial.println ("  ");
Serial.println (sensorval);
delay(250);
}

What did that look like in the temp. range between 30 and 48 c ?

EDIT: I meant for the first two Serial.print not Serial.println.

since I had trouble keeping a constant temperature for testing I had to play with the numbers again. We had established that the sensor is working as expected so no need to do these tests again.

I used an ice cube to get the 0 C value and my own body temp (from fingertips) I used regular digital body thermometer for 34 C.

so I used these values to map it and I got something like this:

int sensorpin = A0;

void setup () {
Serial.begin(9600);
}

void loop () {

int sensorval = analogRead(sensorpin);
int tempC = map(sensorval, 320, 348, 0, 34);
Serial.print (tempC);
Serial.print (" ");
Serial.println (sensorval);
delay(250);

}

I tested several times and it seems to be working just fine with the temperatures from 0 to 34. seems accurate. I tried cigarette lighter flame to get some extreme high temperatures for a brief second, the C value went up to 141 for a second. Since i'm not sure if it's right or not I can't say if it's accurate but it's certainly better than before. I'll do some more testing and post the results :slight_smile:

That's great. Is the resolution within the range you can live with. If not, there may be a few more things we could try. But If acceptable, then no need.
Yes, let us know how it progresses.

well I'd actually need it to sense temperatures 150-300 :slight_smile:
I found one heating element from home which I turned on and took readings from with the laser temp gun ( I know it's not that accurate but at least I get some idea of how hot it is). It showed me ~500 C. I then placed the sensor on top of the element surface and got a reading of ~240 C. half off :roll_eyes:

LOL, I am not sure what you just said meant.
Actually, I think that sensor is not real linear. Meaning you may want to have 2 or 3 map() areas. One for the 10c area, one for the 70c area, and one for the 300c area.

What do you think?

LOL, I am not sure what you just said meant.
Actually, I think that sensor is not real linear. Meaning you may want to have 2 or 3 map() areas. One for the 10c area, one for the 70c area, and one for the 300c area.

What do you think?

EDIT: BTW, you will need a way to celebrate this system. Depending on which you think is the most accurate. Maybe the resistance reading (web page calculator, or your other thermometers). Don't use your thumb at 300C tho, lol

btw. I understood that when I connect the sensor the other way around (swap 5v and ground) then I get a reading that is decreasing instead of increasing. What really happened is that on one occasion the value started to cound around 320 (0 C) and after swapping 5v ang gnd the count started around ~600. both were increasing...

also, according to this
http://openenergymonitor.org/emon/buildingblocks/rtd-temperature-sensing
the temp accuracy of 2-3C should be enough for me.

and I entered the numbers from pt100 datasheet into excel to see how the resistance changes over temperature. The growth is very linear I must say...