Saturday, January 5, 2013

All cleaned up and re-mounted

A nice clean board (actually, i just flipped the old one over) and all components re-mounted.  System is up and running 24/7 now.
The Cleanly Re-Mounted Alarm/Automation System

Reading Temperature With Thermistors

My first interest for an analog input is a probe to read the temperature in my beer fridge. (I am a home brewer and occasionally need closely controlled temperature for fermenting lagers.) There were a couple of 10K ohm thermistors in my box of misc components, so I decided to try those. Something like the TMP36 sensor may be a better choice, and I will try some of those soon.

A thermistor is a special type of resistor that changes resistance with temperature.  A 10KΩ thermistor is 10KΩ at 25°C.  The first problem to solve is how to use the thermistor to produce a voltage that the MPC3008 analog to digital converter can read.  A simple voltage divider, as show in the diagram here, will do the trick.

The thermistor is R1, R2 is 10KΩ, and Vin is 5V.  This will make Vout = 2.5V at 25°C.  The chart for this thermistor shows that it should vary from 1.3V at 32°F to 2.9V at 95°F.  Setting the reference voltage on the MPC3008 to 3.3V will provide the best resolution for this range. I took test measurements by placing the thermistor in an insulated cup of water ranging from ice water to very warm.  Well, that was the plan anyway.  Reminder to self: when using a thermistor or other sensor in water, shrink tubing won't cut it.  I got a rude reminder of this when I first tried to do a calibration.

My solution to the waterproofing was to simply encase the thermistor and connecting wire in epoxy.  I formed a small mold using wax paper, filled it with freshly mixed epoxy, and pushed the sensor into the epoxy.  Once it dried, I trimmed it and it came out looking like this.

I took test measurements successfully and put the data into Excel. The plot of this data shows, as expected,  a very linear curve.  Putting this data into a Least Squares Fit function produced a slope of 0.13239 and an intercept of -14.402.  This gives me parameters to convert from counts to degrees with reasonable accuracy.  Once in use I will probably need to tweak the intercept value for individual sensors due to variations in the components.

The MPC3008 is a 10 bit ADC, meaning that it will output a value between 0 and 1023.  This corresponds to zero and reference volts.  For example, if the reference is 5V, an input of 2.5V would give an output of 512 counts.  To convert from counts to volts:

            V = Vref *counts/1024

Now that I have the data from my earlier calibration, I can simply use that to convert directly from counts to degrees F.

           Temp = -14.402 + (Counts * 0.13239)

My automation/alarm software has now been enhanced to read the analog data and convert it to real values using the provided conversion parameters.  I am now monitoring the temperature in my beer fridge and once I set up a large relay to control the power, I will be able to finely control the temperature and maybe brew a decent lager.