<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hmmm.... &#187; thermistor</title>
	<atom:link href="http://michael.thegrebs.com/tag/thermistor/feed/" rel="self" type="application/rss+xml" />
	<link>http://michael.thegrebs.com</link>
	<description></description>
	<lastBuildDate>Thu, 27 Oct 2011 18:48:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Quick &amp; Easy Temperature Logging with the Arduino</title>
		<link>http://michael.thegrebs.com/2008/11/02/arduino-temperature-logging/</link>
		<comments>http://michael.thegrebs.com/2008/11/02/arduino-temperature-logging/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 03:29:50 +0000</pubDate>
		<dc:creator>mikegrb</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[thermistor]]></category>

		<guid isPermaLink="false">http://michael.thegrebs.com/?p=137</guid>
		<description><![CDATA[Basic Voltage Divider with a Thermistor: Typical voltage divider, matched would have made better sense but the thermistor was a random one salvaged from consumer electronics so I didn&#8217;t know the value in advance. Would work just fine like this &#8230; <a href="http://michael.thegrebs.com/2008/11/02/arduino-temperature-logging/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Basic Voltage Divider with a Thermistor:</strong></p>
<p><img src='http://thegrebs.com/~michael/therm-vd.png' alt='Thermistor Voltage Divider Schematic' class='alignleft' /></p>
<p>Typical voltage divider, matched would have made better sense but the thermistor was a random one salvaged from consumer electronics so I didn&#8217;t know the value in advance.</p>
<p>Would work just fine like this with TP1 connected to an Arduino analog input and Vcc and GND connected.  Energy savings for the win though, connected the top of the divider (Vcc) to a digital pin on the Arduino.  Set the pin HIGH when you want to take a reading, LOW the rest of the time.  Now the divider is not consuming power when a reading isn&#8217;t being taken.</p>
<p><strong>Arduino Code</strong></p>
<div class="codecolorer-container c vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> pinDivEn &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> pinDivRead <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> pinLED &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000dd;">13</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; pinMode<span style="color: #009900;">&#40;</span>pinLED<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; pinMode<span style="color: #009900;">&#40;</span>pinDivEn<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;READY&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>pinDivEn<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>pinLED<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> serByte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>analogRead<span style="color: #009900;">&#40;</span>pinDivRead<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>pinDivEn<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>pinLED<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>pinDivEn is the divider enable pin (Vcc), pinDivRead is the analog input connected to TP1 in the divider, pinLED is is a digital pin with an LED that is lit while a reading is taken.</p>
<p>Once the Arduino boots it sends READY on the serial port at 9600 bps.  It then waits for any data to be available on the serial port, when bytes are available, the voltage divider is enabled, the LED is lit, the bytes on the serial port are consumed, the value of TP1 is read and then written to the serial port, the divider enable pin is brought back low and the led is extinguished.</p>
<p><strong>Perl Code</strong></p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Handle</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> Device<span style="color: #339933;">::</span><span style="color: #006600;">SerialPort</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dev</span> <span style="color: #339933;">=</span> <span style="color: #000066;">tie</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">*FH</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Device::SerialPort'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;/dev/tty.usbserial-A4001JwW&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't tie: $!&quot;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #0000ff;">$dev</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">baudrate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000ff;">$dev</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">databits</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000ff;">$dev</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">parity</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000ff;">$dev</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">stopbits</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066;">open</span> <span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$log</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'&gt;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'ohms.log'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;can't open: $!&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">autoflush</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># wait for arduino to boot</span><br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$val</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;fh&gt;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">last</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$val</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066;">print</span> FH <span style="color: #ff0000;">&quot;1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$val</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;/</span>fh<span style="color: #339933;">&gt;</span><span style="color: #009999;">&lt;fh&gt;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">next</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$val</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$val</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vR2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$val</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1023</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vR1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$vR2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000ff;">$vR1</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1</span>_000 <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1</span>_000<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$R2</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #0000ff;">$vR2</span> <span style="color: #339933;">/</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066;">print</span> <span style="color: #0000ff;">$log</span> <span style="color: #000066;">time</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">' '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$R2</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># printf(&quot;V_R2=%.2fV, i=%.2fmA &nbsp;R2=%.2fK&amp;#8486;\n&quot;, $vR2, $i, $R2);</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066;">sleep</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">print</span> FH <span style="color: #ff0000;">&quot;1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Opens the serial port, waits for something (the Arduino sending &#8216;READY&#8217; but it pays no attention to what) on the serial port then every 10 seconds sends a 1\n to the Arduino prompting it to send a value.  The result of analogRead is an integer from 0 &#8211; 1023 so this is converted to a voltage.  The current through the divider is found allowing the resistance of the thermistor to be solved for.  The resistance and time are written to a space separated log file.  If the thermistor wasn&#8217;t unknown it would make more sense to solve for the actual temp using the Steinhart–Hart equation or similar and logging that rather than the resistance.</p>
<p><strong>Sample log file entries</strong></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">1224349429 10.1195652173913<br />
1224349439 10.3666666666667<br />
1224349449 10.3666666666667<br />
1224349459 10.3666666666667<br />
1224349469 10.4943820224719<br />
1224349479 10.3666666666667<br />
1224349489 10.2417582417582</div></div>
<p>A few lines in a text file gets us a graph from the log file by way of GnuPlot:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">set term png transparent nocrop enhanced font &quot;./arial.ttf&quot; 9 size 800, 600<br />
set xdata time<br />
set timefmt &quot;%s&quot;<br />
set format x &quot;%m/%d %H:%M&quot;<br />
set xtics &nbsp;rotate by -45<br />
set title &quot;Thermistor Value&quot;<br />
set xlabel &quot;Date/Time&quot;<br />
set ylabel &quot;Resistance (kOhms)&quot;<br />
set grid<br />
set output &quot;ohms.png&quot;<br />
plot \<br />
&nbsp; &nbsp; &quot;ohms.log&quot; using 1:2 title &quot;10 sec interval readings&quot; linecolor 2, \<br />
&nbsp; &nbsp; &quot;ohms.log&quot; using 1:2 title &quot;Bezier fit curve&quot; smooth bezier linecolor 4 lw 2, \<br />
&nbsp; &nbsp; 10 title &quot;77 F&quot; lw 2 linecolor 1</div></div>
<p><img src='http://thegrebs.com/~michael/ohms.png' alt='GnuPlot Graph of Time vs Resistance' class='alignnone' /></p>
<p></fh></p>
]]></content:encoded>
			<wfw:commentRss>http://michael.thegrebs.com/2008/11/02/arduino-temperature-logging/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

