Sciencemadness Discussion Board
Not logged in [Login ]
Go To Bottom

Printable Version  
Author: Subject: NTC Thermistor and Arduino brief tutorial
smaerd
International Hazard
*****




Posts: 1262
Registered: 23-1-2010
Member Is Offline

Mood: hmm...

[*] posted on 30-8-2015 at 06:18
NTC Thermistor and Arduino brief tutorial


Sorry I haven't been around I've been super busy. So this is a very small project but I figured it might help someone out. I won't dive into the theory or anything as it's not that hard. This is an entry level tutorial, if you want more then learn it and share it.

I purchased a NTC thermistor for about 1-2$ USD not long ago. It didn't come with documentation but the specifications were listed as -
Quote:
Stainless steel sheath and waterproof
Measurement range: -40 to 120 °C
Type: NTC
Resistance: 10k
B-constant : 3435K -/+ 1%

The most important thing here is knowing the maximum resistance(10K ohm) for purposes of having the arduino make a measurement. The arduino's ADC measures counts based on voltages which are easily converted to voltages. But it does not measure resistances so the simplest way to turn a varying resistance into a measurable voltage is what is called a voltage divider circuit(https://en.wikipedia.org/wiki/Voltage_divider).

Untitled.png - 11kB
(image courtesy of wikipedia page)

A resistive DC voltage divider can be expressed as this equation: (image courtesy of wikipedia page)
Because the thermistor has a 10k Ohm resistance I selected R1 to be ~10k Ohm as well. Which is sensible looking at the equation.

It's important to actually measure the resistance of your R1 resistor to get a more accurate value. As resistors vary from their package description. 1% resistors are ideal and cheap. It's also important to measure the voltage of the 5V power from the arduino or whatever external power source you use. The ADC counts depend on that.

To physically create the circuit connect a 5V line from the arduino to the voltage divider and lead that back to the ground. Put an analog pin(I chose A0) where the resistor and thermistor meet in series. I have attached an image which is of horrendous quality(I artificially sharpened it) of the bread board I used.

DSCF0069.JPG - 389kB

Now the thermistor does not operate in a linear manner by any means. The B or beta parameter is given which can be used in a simplified way to retrieve temperature measurements (https://en.wikipedia.org/wiki/Thermistor). Thankfully the arduino can handle logarithm's and powers because the equation turns out to be this one -

where
(images courtesy of wikipedia page)

For all intensive purposes the Rinfinite can be regarded as a constant and implemented as such in the code. For a more accurate rendering of a thermistor the use of the Stienhart-Hart equation is advised.

The arduino code is attached below. If there's any errors with it just let me know I tidied it up without compiling before uploading.

Attachment: thermometer2.ino (1kB)
This file has been downloaded 1243 times

--------------
How well does it work?
Well, I don't have anything to test it against at the moment. However,

Icey tap water reads about 1.5-2.0*C. (A little high maybe)
Tap water shortly after being boiled is around 95*C. (A little low maybe)
Room temperature with air conditioning is about 26*C. (A little high maybe)
Body temperature read 37.1-37.3*C (A little high but close if not accurate)

The readings are probably not absolute. For a 2 USD thermistor and a 5 USD microcontroller (if you purchase a clone), the head-way into temperature measurements, automation, (basic) calorimetry, or data logging is very accessible and easily implementable.

Hope this "tutorial" helps people understand the basic premise of how to use a NTC Thermistor and encourages some tinkering. I mostly made it so if I get sick I can take my temperature, and because it was a very cheap fun way to spend an hour.

[Edited on 30-8-2015 by smaerd]




View user's profile View All Posts By User
aga
Forum Drunkard
*****




Posts: 7030
Registered: 25-3-2014
Member Is Offline


[*] posted on 30-8-2015 at 11:34


For non-critical stuff, the good old y = mx + c works pretty well despite sensor non-linear behaviour.

Pretty sure i implemented that in the Smelty code somewhere.

Glad to see you back smaerd.




View user's profile View All Posts By User
m1tanker78
National Hazard
****




Posts: 685
Registered: 5-1-2011
Member Is Offline

Mood: No Mood

[*] posted on 30-8-2015 at 12:41


These thermistors are great to have on hand and provide a robust way (once calibrated) to monitor instrument temperature and put the unused analog pins to good use.

Nice tutorial




Chemical CURIOSITY KILLED THE CATalyst.
View user's profile View All Posts By User
smaerd
International Hazard
*****




Posts: 1262
Registered: 23-1-2010
Member Is Offline

Mood: hmm...

[*] posted on 30-8-2015 at 13:29


@aga - thanks, grad school has been eating a lot of my time!

Oo I had never seen the smelty before awesome job on that! I see, yes thermistors are very non-linear whereas the thermocouple you used is quite linear so y=mx+b is fine. I actually tried a similar route before reading about thermistors and was getting some very peculiar values.

@m1tanker78 - That's a smart idea I'll definitely be thinking about that for some future projects.




View user's profile View All Posts By User
aga
Forum Drunkard
*****




Posts: 7030
Registered: 25-3-2014
Member Is Offline


[*] posted on 30-8-2015 at 13:31


grad school ?

What's that ?




View user's profile View All Posts By User
smaerd
International Hazard
*****




Posts: 1262
Registered: 23-1-2010
Member Is Offline

Mood: hmm...

[*] posted on 30-8-2015 at 16:43


It's the college after college to contribute to the scientific community and earn a doctoral or masters degree.



View user's profile View All Posts By User
Bright Spark
Harmless
*




Posts: 23
Registered: 1-3-2015
Member Is Offline

Mood: No Mood

wink.gif posted on 31-8-2015 at 21:52


Nice tutorial and I am impressed with both your programming and your maths skills

When I use thermistors in the commercial world I always model them as a polynomial, usually the manufacturers of the thermistors give the resistance across the range and it can be within 1% so a polynomial defined with macros means that is can be so easy to change the thermistor to a totally different one and only have to change a few macros

The Steinhart equation isn't very accurate over a wide range, IIRC its accurate over a range about 50C

Don't take this as me being negative, thats not the case I am just explaining another way this can be done

I can show you what I mean if you are interested, the voltage can be eliminated from the equations if the ADC reference voltage is the same as the thermistor bridge supply voltage and this means better accuracy

Regards

[Edited on 1-9-2015 by Bright Spark]

[Edited on 1-9-2015 by Bright Spark]
View user's profile View All Posts By User
aga
Forum Drunkard
*****




Posts: 7030
Registered: 25-3-2014
Member Is Offline


[*] posted on 31-8-2015 at 23:23


Wooo ! Sounds good.

Please show.




View user's profile View All Posts By User
Harristotle
Hazard to Others
***




Posts: 138
Registered: 30-10-2011
Location: Tinkerville
Member Is Offline

Mood: I tink therefore I am

[*] posted on 1-9-2015 at 02:13


There is an even cheaper way to do this. A silicon diode has a negative temperature coefficient of approximately -2mv per degree celsius.
Thus a 1c diode (1n4001 bought in bulk from ebay) makes quite a good thermometer, with callibration. You don't even need to buy a resistor, if you program the analog pins as pullup. Like this:
2015-09-01_1758.png - 13kB

So then your thermometer looks like this:

2015-09-01_1800.png - 39kB

A bit of code to convert the analog reading to degrees, and you are good to go.
I also write mine so that if the arduino sees an X on its serial port, it enters calibration mode and stores the calibration in eeprom. This way you can calibrate on new diodes, or just plug it in and run


<pre>
<font color="#434f54">// a functioning diode thermometer with stored calibration</font>
<font color="#434f54">// To recalibrate, open the serial console and hold down the letter x a few times, then press return, within 1 second of starting</font>
<font color="#434f54">// Then expose the diode to two different, known temperatures. The classic way is with ice water and boiling water, but you</font>
<font color="#434f54">// can use a known thermometer and any two temperatures to callibrate.</font>

<font color="#434f54">//Leon Harris, 2014</font>
<font color="#434f54">// Version: 0.2</font>
<font color="#434f54">// Fully working, but not cleaned up</font>


<font color="#000000">#include</font> <font color="#434f54">&lt;</font><b><font color="#d35400">EEPROM</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">&gt;</font>
<font color="#000000">#include</font> <font color="#434f54">&lt;</font><font color="#000000">avr</font><font color="#434f54">/</font><font color="#000000">eeprom</font><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">&gt;</font> <font color="#434f54">//needed for eeprom_read_block function</font>

<font color="#5e6d03">struct</font> <font color="#000000">calib_t</font>
<font color="#000000">{</font>
&nbsp;<font color="#00979c">float</font> <font color="#000000">slope</font><font color="#000000">;</font>
&nbsp;<font color="#00979c">float</font> <font color="#000000">offset</font><font color="#000000">;</font>
<font color="#000000">}</font> <font color="#000000">calib</font><font color="#000000">;</font>


<font color="#00979c">float</font> <font color="#000000">Temperature</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font>
<font color="#00979c">float</font> <font color="#000000">Slope</font><font color="#434f54">,</font> <font color="#000000">Offset</font><font color="#000000">;</font>
<font color="#00979c">char</font> <font color="#000000">junk</font><font color="#000000">;</font>

<font color="#434f54">// Callibration data goes into Temp[] and Raw[]</font>
<font color="#00979c">float</font> <font color="#000000">Temp</font><font color="#000000">[</font><font color="#000000">2</font><font color="#000000">]</font><font color="#434f54">=</font><font color="#000000">{</font><font color="#000000">0</font><font color="#000000">}</font><font color="#000000">;</font>
<font color="#00979c">int</font> <font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">2</font><font color="#000000">]</font><font color="#434f54">=</font><font color="#000000">{</font><font color="#000000">0</font><font color="#000000">}</font><font color="#000000">;</font>

<font color="#00979c">float</font> <font color="#000000">readTemp</font><font color="#000000">(</font><font color="#000000">;)</font> <font color="#000000">{</font>
&nbsp;<font color="#00979c">float</font> <font color="#000000">raw</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font><font color="#000000">;</font>
&nbsp;<font color="#00979c">float</font> <font color="#000000">temp</font><font color="#000000">;</font>
&nbsp;<font color="#5e6d03">for</font> <font color="#000000">(</font><font color="#00979c">int</font> <font color="#000000">i</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font> <font color="#000000">i</font> <font color="#434f54">&lt;</font> <font color="#000000">5</font><font color="#000000">;</font> <font color="#000000">i</font><font color="#434f54">++</font><font color="#000000">;)</font> <font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;<font color="#000000">raw</font><font color="#434f54">+=</font><font color="#000000">(</font><font color="#00979c">float</font><font color="#000000">;)</font><font color="#d35400">analogRead</font><font color="#000000">(</font><font color="#000000">0</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;
&nbsp;<font color="#000000">}</font>
&nbsp;<font color="#000000">raw</font><font color="#434f54">=</font><font color="#000000">raw</font><font color="#434f54">/</font><font color="#000000">5</font><font color="#000000">;</font>

&nbsp;<font color="#000000">temp</font><font color="#434f54">=</font> <font color="#000000">(</font><font color="#000000">raw</font> <font color="#434f54">*</font> <font color="#000000">Slope</font><font color="#000000">;)</font> <font color="#434f54">+</font> <font color="#000000">Offset</font><font color="#000000">;</font>

&nbsp;<font color="#5e6d03">return</font> <font color="#000000">temp</font><font color="#000000">;</font>
<font color="#000000">}</font>

<font color="#00979c">void</font> <font color="#5e6d03">setup</font><font color="#000000">(</font><font color="#000000">;)</font> <font color="#000000">{</font>

&nbsp;<font color="#434f54">// configure the circuit</font>
<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#000000">A0</font><font color="#434f54">,</font><font color="#00979c">INPUT_PULLUP</font><font color="#000000">;)</font><font color="#000000">;</font>
<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#000000">A1</font><font color="#434f54">,</font><font color="#00979c">OUTPUT</font><font color="#000000">;)</font><font color="#000000">;</font>
<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">A1</font><font color="#434f54">,</font><font color="#00979c">LOW</font><font color="#000000">;)</font><font color="#000000">;</font>

&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">9600</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"Arduino Thermometer"</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"type xxx [enter] within a second to callibrate"</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">flush</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">1000</font><font color="#000000">;)</font><font color="#000000">;</font>

&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#00979c">char</font><font color="#000000">;)</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">read</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#434f54">==</font><font color="#00979c">'x'</font><font color="#000000">;)</font><font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">for</font> <font color="#000000">(</font><font color="#00979c">int</font> <font color="#000000">i</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font> <font color="#000000">i</font> <font color="#434f54">&lt;</font> <font color="#000000">512</font><font color="#000000">;</font> <font color="#000000">i</font><font color="#434f54">++</font><font color="#000000">;)</font><font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">EEPROM</font></b><font color="#434f54">.</font><font color="#d35400">write</font><font color="#000000">(</font><font color="#000000">i</font><font color="#434f54">,</font><font color="#000000">0</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
&nbsp;<font color="#000000">}</font>
&nbsp;
&nbsp;
&nbsp;<font color="#434f54">// check for callibration data</font>
<font color="#000000">eeprom_read_block</font><font color="#000000">(</font><font color="#000000">(</font><font color="#00979c">void</font><font color="#434f54">*</font><font color="#000000">;)</font><font color="#434f54">&</font><font color="#000000">calib</font><font color="#434f54">,</font> <font color="#000000">(</font><font color="#00979c">void</font><font color="#434f54">*</font><font color="#000000">;)</font><font color="#000000">0</font><font color="#434f54">,</font> <font color="#5e6d03">sizeof</font><font color="#000000">(</font><font color="#000000">calib</font><font color="#000000">;)</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">slope</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#00979c">" "</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">offset</font><font color="#000000">;)</font><font color="#000000">;</font>
<font color="#5e6d03">if</font> <font color="#000000">(</font> <font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">slope</font> <font color="#434f54">==</font> <font color="#000000">0</font> <font color="#000000">;)</font> <font color="#000000">{</font> <font color="#434f54">//no slope, no calibration</font>
&nbsp;<font color="#434f54">// start calibration routine</font>

&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"Enter first temperature on the serial console"</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">flush</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">while</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">;)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">;)</font> <font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">junk</font><font color="#434f54">=</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">read</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
&nbsp;<font color="#5e6d03">while</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">;)</font> <font color="#434f54">==</font> <font color="#000000">0</font><font color="#000000">;)</font> <font color="#000000">{</font>
&nbsp;&nbsp;<font color="#000000">Temp</font><font color="#000000">[</font><font color="#000000">0</font><font color="#000000">]</font><font color="#434f54">=</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">parseFloat</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>

&nbsp;<font color="#000000">}</font>
&nbsp;<font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">0</font><font color="#000000">]</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font>
<font color="#5e6d03">for</font> <font color="#000000">(</font><font color="#00979c">int</font> <font color="#000000">i</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font> <font color="#000000">i</font> <font color="#434f54">&lt;</font> <font color="#000000">10</font><font color="#000000">;</font> <font color="#000000">i</font><font color="#434f54">++</font><font color="#000000">;)</font><font color="#000000">{</font>
&nbsp;&nbsp;<font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">0</font><font color="#000000">]</font><font color="#434f54">+=</font><font color="#d35400">analogRead</font><font color="#000000">(</font><font color="#000000">0</font><font color="#000000">;)</font><font color="#000000">;</font>
<font color="#000000">}</font>

&nbsp;<font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">0</font><font color="#000000">]</font><font color="#434f54">=</font><font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">0</font><font color="#000000">]</font><font color="#434f54">/</font><font color="#000000">10</font><font color="#000000">;</font>


&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"Enter second temperature on the serial console"</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">flush</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">while</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">;)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">;)</font> <font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">junk</font><font color="#434f54">=</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">read</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;<font color="#5e6d03">while</font> <font color="#000000">(</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">available</font><font color="#000000">(</font><font color="#000000">;)</font> <font color="#434f54">==</font> &nbsp;<font color="#000000">0</font><font color="#000000">;)</font> <font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;<font color="#000000">Temp</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font><font color="#434f54">=</font><b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">parseFloat</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;<font color="#000000">}</font>

&nbsp;&nbsp;&nbsp;<font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font>
<font color="#5e6d03">for</font> <font color="#000000">(</font><font color="#00979c">int</font> <font color="#000000">i</font><font color="#434f54">=</font><font color="#000000">0</font><font color="#000000">;</font> <font color="#000000">i</font> <font color="#434f54">&lt;</font> <font color="#000000">10</font><font color="#000000">;</font> <font color="#000000">i</font><font color="#434f54">++</font><font color="#000000">;)</font><font color="#000000">{</font>
&nbsp;&nbsp;<font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font><font color="#434f54">+=</font><font color="#d35400">analogRead</font><font color="#000000">(</font><font color="#000000">0</font><font color="#000000">;)</font><font color="#000000">;</font>
<font color="#000000">}</font>

&nbsp;<font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font><font color="#434f54">=</font><font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font><font color="#434f54">/</font><font color="#000000">10</font><font color="#000000">;</font>

<font color="#434f54">// slope and intercept calculations go here</font>
<font color="#000000">Slope</font><font color="#434f54">=</font> <font color="#000000">(</font><font color="#000000">Temp</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font> <font color="#434f54">-</font> <font color="#000000">Temp</font><font color="#000000">[</font><font color="#000000">0</font><font color="#000000">]</font><font color="#000000">;)</font><font color="#434f54">/</font> <font color="#000000">(</font><font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font> <font color="#434f54">-</font> <font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">0</font><font color="#000000">]</font><font color="#000000">;)</font><font color="#000000">;</font>
<font color="#000000">Offset</font><font color="#434f54">=</font> <font color="#000000">Temp</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font> <font color="#434f54">-</font> <font color="#000000">(</font> <font color="#000000">Slope</font> <font color="#434f54">*</font> <font color="#000000">Raw</font><font color="#000000">[</font><font color="#000000">1</font><font color="#000000">]</font><font color="#000000">;)</font> <font color="#000000">;</font>

<font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">slope</font><font color="#434f54">=</font><font color="#000000">Slope</font><font color="#000000">;</font>
<font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">offset</font><font color="#434f54">=</font><font color="#000000">Offset</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"#############################################################"</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"# &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"</font><f ont color="#000000">;)</font><font color="#000000">;</font>
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#00979c">"# Slope= "</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">slope</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b> <font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"</fon t><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#00979c">"# Offset= "</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">offset</font><font color="#000000">;)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#"</font><font color="#000000">;)</font><font color="#000000">;</font>
<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#00979c">"#############################################################"</font><font color="#000000">;)</font><font color="#000000">;</font>

<font color="#000000">eeprom_write_block</font><font color="#000000">(</font><font color="#000000">(</font><font color="#00979c">const</font> <font color="#00979c">void</font><font color="#434f54">*</font><font color="#000000">;)</font><font color="#434f54">&</font><font color="#000000">calib</font><font color="#434f54">,</font> <font color="#000000">(</font><font color="#00979c">void</font><font color="#434f54">*</font><font color="#000000">;)</font><font color="#000000">0</font><font color="#434f54">,</font> <font color="#5e6d03">sizeof</font><font color="#000000">(</font><font color="#000000">calib</font><font color="#000000">;)</font><font color="#000000">;)</font><font color="#000000">;</font>
<font color="#000000">}</font> <font color="#434f54">//end if</font>

<font color="#5e6d03">else</font> <font color="#000000">{</font>
<font color="#000000">Slope</font><font color="#434f54">=</font><font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">slope</font><font color="#000000">;</font>
<font color="#000000">Offset</font><font color="#434f54">=</font><font color="#000000">calib</font><font color="#434f54">.</font><font color="#000000">offset</font><font color="#000000">;</font>
<font color="#000000">}</font>

<font color="#000000">}</font>




<font color="#00979c">void</font> <font color="#5e6d03">loop</font><font color="#000000">(</font><font color="#000000">;)</font> <font color="#000000">{</font>

<font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">1000</font><font color="#000000">;)</font><font color="#000000">;</font>

<font color="#000000">Temperature</font><font color="#434f54">=</font><font color="#000000">readTemp</font><font color="#000000">(</font><font color="#000000">;)</font><font color="#000000">;</font>


<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">Temperature</font><font color="#000000">;)</font><font color="#000000">;</font>

<font color="#000000">}</font>

</pre>



[Edited on 1-9-2015 by Harristotle]
View user's profile View All Posts By User
aga
Forum Drunkard
*****




Posts: 7030
Registered: 25-3-2014
Member Is Offline


[*] posted on 1-9-2015 at 08:44


Quote:
eeprom_read_block((void*)&calib, (void*)0, sizeof(calib));

Wooo !

Didn't know the EEPROM library had a block read/write function.

A+ for cheapest, easiest temperature sensor.

I get the feeling that we're wanting accuracy over a greater range of temperatures though.




View user's profile View All Posts By User
smaerd
International Hazard
*****




Posts: 1262
Registered: 23-1-2010
Member Is Offline

Mood: hmm...

[*] posted on 1-9-2015 at 09:40


Quote: Originally posted by Bright Spark  

The Steinhart equation isn't very accurate over a wide range, IIRC its accurate over a range about 50C


Brightspark that's really good to know.

I'd love to see how thermistors are handled in a professional context. It's interesting you use a polynomial model but why not! I think I see what you mean about ripping out the voltages. Anything you want to share I'd love to read.

@Haristotle
I am really impressed with this. It's one of those backwoods solutions I probably would have never considered yet have them(diodes) sitting on my shelf. 2mv increment per degree celsius is quite nice for a wider temperature range sacrificing some resolution(depending on the circumstance). It's also a lot quicker once calibrated which is great for a cheap and dirty on board temperature measurement.

For external sensing a little thermowell could be made without any issue and very cheaply I am sure as well.

Thanks for providing your code. I also didn't know about the EEPROM commands but I never dabbled much with EEPROM.




View user's profile View All Posts By User
aga
Forum Drunkard
*****




Posts: 7030
Registered: 25-3-2014
Member Is Offline


[*] posted on 1-9-2015 at 11:38


Amazing, I thought i'd seen the diode thing before.

Page 139 of the Microchip PIC16F1823 manual shows the schematic of the die-temperature sensor, and it's two or 4 diodes.

Edit:

Got the part code wrong

[Edited on 1-9-2015 by aga]




View user's profile View All Posts By User
Harristotle
Hazard to Others
***




Posts: 138
Registered: 30-10-2011
Location: Tinkerville
Member Is Offline

Mood: I tink therefore I am

[*] posted on 2-9-2015 at 01:14
one last trick


one last qute trick that I normally use, but for some reason did not put in that example: you can increase your resolution 5x by using:
AnalogReference(INTERNAL);

this sets your adc to read 0-1.1volt.
So your diode will give you about 630 counts at room temp, instead of only 140 counts. ie 0.9 bits per millivolt instead of 0.2 volts per mv. In other words, about +/- 0.5 a degree resolution, if you use the internal reference, which is 1.1 volt.

Cheers,
H.
View user's profile View All Posts By User
smaerd
International Hazard
*****




Posts: 1262
Registered: 23-1-2010
Member Is Offline

Mood: hmm...

[*] posted on 13-9-2015 at 04:46


Very nice! I had no idea that the ADC potential range could be changed like that. When I looked into it some more I read in other places that the arduino ADC isn't exactly a gold standard by simply using analogread() due to supply voltage fluctuations, etc.

A circuit based solution - http://www.skillbank.co.uk/arduino/measure.htm
A 'low-level' code based solution - http://hacking.majenko.co.uk/making-accurate-adc-readings-on...




View user's profile View All Posts By User
IrC
International Hazard
*****




Posts: 2710
Registered: 7-3-2005
Location: Eureka
Member Is Offline

Mood: Discovering

[*] posted on 15-11-2015 at 09:34


Just wanted to share a couple sites I have been spending much time at lately which can aid in using your Arduino for many complex tasks involving automation. Tutorials useful in learning how to monitor sensors and performing various functions in the lab. This thread seemed to be an appropriate place to share these links for those who have not already found them.

http://howtomechatronics.com/

https://processing.org/





"Science is the belief in the ignorance of the experts" Richard Feynman
View user's profile View All Posts By User
annaandherdad
Hazard to Others
***




Posts: 387
Registered: 17-9-2011
Member Is Offline

Mood: No Mood

[*] posted on 15-11-2015 at 15:07


Thanks, everyone, for this thread. It's things like this that keep me coming back to SM.



Any other SF Bay chemists?
View user's profile View All Posts By User
aga
Forum Drunkard
*****




Posts: 7030
Registered: 25-3-2014
Member Is Offline


[*] posted on 15-11-2015 at 15:19


It's things like your QM posts that keep me coming back !

Do you have a specific Arduino project in mind ?




View user's profile View All Posts By User
Junaid_Shahid
Harmless
*




Posts: 1
Registered: 20-5-2017
Member Is Offline

Mood: No Mood

[*] posted on 20-5-2017 at 01:28


Quote: Originally posted by IrC  
Just wanted to share a couple sites I have been spending much time at lately which can aid in using your Arduino for many complex tasks involving automation. Tutorials useful in learning how to monitor sensors and performing various functions in the lab. This thread seemed to be an appropriate place to share these links for those who have not already found them.

http://howtomechatronics.com/

https://processing.org/



That's really nice, But I will like to add some more right below your suggestions.

https://www.theengineeringprojects.com
http://www.instructables.com/tag/type-id/category-technology...
View user's profile View All Posts By User
Melgar
Anti-Spam Agent
*****




Posts: 2004
Registered: 23-2-2010
Location: Connecticut
Member Is Offline

Mood: Estrified

[*] posted on 22-5-2017 at 00:28


Quote: Originally posted by Junaid_Shahid  
Quote: Originally posted by IrC  
Just wanted to share a couple sites I have been spending much time at lately which can aid in using your Arduino for many complex tasks involving automation. Tutorials useful in learning how to monitor sensors and performing various functions in the lab. This thread seemed to be an appropriate place to share these links for those who have not already found them.

http://howtomechatronics.com/

https://processing.org/



That's really nice, But I will like to add some more right below your suggestions.

https://www.theengineeringprojects.com
http://www.instructables.com/tag/type-id/category-technology...

Really, this entire thread is pretty much obsolete. You can get a MAX 6675 thermocouple reader from China for about $2, and the corresponding K-type thermocouple for about $1.50. Then you just download the library, and you can measure virtually any temperature up to the melting point of the shielding on the thermocouple wires, and more accurately than a thermistor as well.
View user's profile View All Posts By User
Sulaiman
International Hazard
*****




Posts: 3692
Registered: 8-2-2015
Location: 3rd rock from the sun
Member Is Offline


[*] posted on 22-5-2017 at 03:04


Or you could buy a rex c100 temperature controller
£6.99 rex-c100 http://www.ebay.co.uk/itm/382084805756?_trksid=p2060353.m143...
£8.29 rex-c100 + 40A ssr + thermocouple probe http://www.ebay.co.uk/itm/Digital-PID-Temperature-Control-40...

or a four channel temperature meter with four thermocouples £16.62 http://www.ebay.co.uk/itm/Digital-Thermometer-4-Channel-200-...

or just a thermistor probe with digital panel meter £0.99 http://www.ebay.co.uk/itm/DIGITAL-DISPLAY-FRIDGE-FREEZER-PRO...




CAUTION : Hobby Chemist, not Professional or even Amateur
View user's profile View All Posts By User
Texium
Administrator
Thread Moved
27-11-2023 at 11:23

  Go To Top