BioBoard/Documentation/Temperature: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
No edit summary
No edit summary
Line 93: Line 93:
and the math part is the Steinhart-Hart equation, which is the relationship between the resistance and the temperature for a thermistor with certain materials properties (see here for a description).  On the manufacturer's datasheet for your specific resistor you will find a list of 4 materials constants - usually referred to as A, B, C, and D - that go with it.  The most general equation is:  
and the math part is the Steinhart-Hart equation, which is the relationship between the resistance and the temperature for a thermistor with certain materials properties (see here for a description).  On the manufacturer's datasheet for your specific resistor you will find a list of 4 materials constants - usually referred to as A, B, C, and D - that go with it.  The most general equation is:  


Center|1/T= A + B*ln(R/Rt) + C*ln(R/Rt)<sup>2</sup> + D*ln(R/Rt)<sup>3</sup>
1/T= A + B*ln(R/Rt) + C*ln(R/Rt)<sup>2</sup> + D*ln(R/Rt)<sup>3</sup>


but check which one is appropriate for the material constants on your datasheet (the ones in this example are for Vishay thermistors which come from Sparkfun).
but check which one is appropriate for the material constants on your datasheet (the ones in this example are for Vishay thermistors which come from Sparkfun).

Revision as of 20:59, 2 May 2011

Introduction to temperature measurements

We are all familiar with the classic simple analog thermometer - the one with the resevoir of mercury or alcohol at the bottom. Unfortunately it is not very easy to convert the (optical) readings from this into a digital format so that we can datalog the information from our experiments. But with the Arduino we can take an analog electrical signal and turn it into a digital one that we can use. We have a number of choices so we need to choose the best ones for the BioBoard, where we'll be doing measurements on biological systems so the temperature range is generally the same as the one for liquid water. We want inexpensive, readily available, sensors that are easy to implement with the Arduino - and have the appropriate range, precision, and accuracy.

Some of the basic types of electronic temperature sensors include:

  • thermocouple - excellent for very wide temperature ranges, up to 2300°C
  • resistance temperature detector (RTD) - used up to 600°C, often for industrial applications
  • thermistor - generally limited to <150°C, but inexpensive
  • digital temperature sensor (DTS) - the output is linearly proportional to the temperature
relative sizes of the two sensors

The thermocouple may be seem to be the most versatile - the individual sensors can be quite inexpensive (but to make your own can mean buying enough materials for many probes) and the range large - but the millivolt output requires an amplifier (~$18) to make them compatible with the Arduino, and they have a greater range than we need. RTDs are becoming increasingly common for some applications but require a bridge circuit, and are not as inexpensive or commonly available as we would like. We chose to focus on both the thermistor and the DTS because they cover the temperature range of choice well, they are inexpensive, and they can be implemented on the Arduino easily - you get two choices, just in case you have a preference, or one is more easily available than the other. The photo shows the 2 sensors that we interfaced (the DTS is the 3 wire one), but note that the digital sensor also comes in a smaller surface mount configuration, and thermistors can be as small as a grain of sand.

Building a thermometer

Since your temperature probe will be exposed to moisture or liquid water, it is best to encase it in a waterproof sheath - a good way to do it might be to place it in a plastic tube and seal both the thermistor/DTS end and the wires coming out the far end with silicone aquarium sealant. Leave the tip of the thermistor or DTS exposed, so that you will have a good response time.

Digital thermometer

The digital temperature sensor is the new kid on the block - it is a chip made by such manufacturers as Maxim/Dallas, Philips, and Texas Instruments, and is made to run off a voltage from 3 to 5.5 VDC, just like the Arduino puts out. We used the Maxim DS18B20 (Sparkfun and Hacktronics carry them for ~$4 but you can find them for less) and each sensor has unique 64 bit serial code stored in an onboard ROM - this allows you to use more than one sensor at a time. It is rated for the range -55°C to +125°C and has a stated accuracy of +/-.5°C in the range -10°C to +85°C.

What you need

  • digital temperature sensor such as the Maxim DS18B20
  • 1" / 25mm piece of acrylic tube
  • Wire - you'll need 3 different colours; we suggest red for power, green for ground and white for signal
  • Heat shrink tubing
  • Aquarium / hot glue
  • 4.7kΩ resistor

How to build it

schematic for the digital temperature sensor

We've been using this very good, easy-to-follow DTS tutorial from Hacktronics - it'll teach you everything you need to know about interfacing with your DTS. We'll try to do the same, and also tell you how to waterproof your DTS for use in liquids.

Step 1: solder wires to the chip; remember to pull the heat shrink on before you solder the joints

Step 2: string acrylic tube piece on wires, leave sensor sticking out about 1" / 25mm. Fill the tube with glue, then pull on the wires to drag the sensor into the tube until the leads are fully covered.

Step 3: On a solderless breadboard, build your simple circuit by connecting the GND / #1 leg of the chip to the GND pin on your Arduino board and the VDD / #3 leg to the power strip on the breadboard. Then connect the DQ / #2 leg of the chip to an empty strip on your breadboard, and wire that to the Arduino's digital pin 3. Last, connect the strip to power / 5V using a 4.7kΩ resistor.


Things to keep in mind

Remember that you need to find the address for your individual sensor and then paste it into your Arduino sketch.

serial port results for the address finder

Keep careful track of which of your wires goes to which pins on the sensor, since once you waterproof your probe it will be hard to tell!





Thermistor

A thermistor is a type of resistor which has a very well known dependence of the resistance on temperature, and the change is quite steep so that we can resolve small differences in temperature. We are using them in place of traditional thermometers, and so they are sometimes referred to a "resistance thermometers" - they are inexpensive, easy to find, and are very easy to interface to the Arduino. They are specified mainly by their room temperature (25°C) resistance and a common value is 10 kOhms. If many models are available, like from a major electronics supply house, you can also specify the tolerance and you can choose from different shapes and sizes (the size of a match head is good for starters). As well, there are two general types of thermistors - ones that increase in resistance with increasing temperature (PTC) and those that decrease in temperature with increasing temperature (NTC).

What you need

Besides your thermistor, all you need for the circuit is a "standard" resistor with a value that is the same as the room temperature resistance of your thermistor. You'll be using the standard one to build a "resistive divider" so that you can use the 5 VDC output of the Arduino and have good resolution over the full temperature range of the thermistor (usually something like -40°C to +125°C, perfect for biological experiments). For our examples we'll be using a 10kΩ NTC thermistor (Sparkfun and Hacktronics carry these) with a 10kΩ resistor for the bridge.

How to build it

Solder on wires and waterproof it as described for the DTS above.

On a breadboard build your simple resistive divider circuit, which looks like this.

schematic for the thermistor temperature sensor


Things to keep in mind

R1 is the thermistor in the circuit, so your standard resistor (R2) is the one tied to the Arduino ground. When you buy the thermistor and matching resistor, buy ones with tight tolerances so that you don't have to worry about small errors in the temperature introduced by values which are off the stated values; and you might measure the actual values with a good digital multimeter, just to make sure. Take care when soldering, so that you don't expose the sensor to too high a temperature - you can fry it; before you waterproof, check the resistance one last time, just to make sure everything is still OK.


Interfacing and measuring

Remember that the Arduino has a digital output with 10 bit (1024) resolution so for the special case where R1 is the same as R2 (that's our situation at room temperature) the voltage will be half of the Arduino's 5 VDC, so we can expect the digital output to be 1024/2 or 512. The code looks like this:

double Thermistor(int RawADC) {
double Temp;
float resistance = (10240000/RawADC) - 10000;    //calculate from voltage divider, for 10k resistor
Temp = log(resistance/10000);
// calculate the temperature, in K, using 4 thermistor model/material specific parameters A, B, C, D
// here we use the values for the Sparkfun/Hacktronics version of the Vishay 10k NTC thermistor (from datasheet)
Temp = 1 / (0.003354016 + 0.0002569850 * Temp + 0.000002620131 * Temp * Temp + 0.00000006383091 * Temp * Temp * Temp);
Temp = Temp - 273.15;            // Convert Kelvin to Celsius
// Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celsius to Fahrenheit
return Temp;
}

and the math part is the Steinhart-Hart equation, which is the relationship between the resistance and the temperature for a thermistor with certain materials properties (see here for a description). On the manufacturer's datasheet for your specific resistor you will find a list of 4 materials constants - usually referred to as A, B, C, and D - that go with it. The most general equation is:

1/T= A + B*ln(R/Rt) + C*ln(R/Rt)2 + D*ln(R/Rt)3

but check which one is appropriate for the material constants on your datasheet (the ones in this example are for Vishay thermistors which come from Sparkfun).


Calibrating a home-built thermometer

results when the thermistor is immersed in ice water
response time of the two sensors
example probes for the two sensors

Everybody needs to be convinced that your homemade instrument is reading what it should - it must be checked for calibration. Most of us only have two easily accessible, well known, temperatures in the biological region of interest that we can produce - the melting point of ice (0°C) and the boiling point of water (100°C, at sea leve)l - and these are good places to start. It can be helpful to use another reference temperature measurement technique which has already been calibrated, such as a commercial digital thermometer, in case or thermocouple (plus a reader for it - I use a Fluke instrument with an adjustable offset in case there is any error at your reference temperatures) is not available. This figure shows the results of a trial where I placed both the thermocouple and the thermistor in an ice+water bath (a double walled coffee mug) and recorded the Arduino output every 10 seconds - both instruments had an efective resolution of .1°C and we are looking at the noise at a fixed temperature.

It is not uncommon to see a peak-to-peak noise level of 3 times the resolution, and that is about what the experiment shows for both the thermistor and thermocouple. Note that for this experiment the Arduino output seems to be linear with the calculated temperature, and this what we expect for relatively small changes in temperature - if we are monitoring experiments where the temperature does not change much we can simplify the mathematical relationship between resistance and temperature, avoiding the calculation hassles of the Steinhart-Hart equation. The offset of ~1.3°C between the "Arduino temperature" and the expected value of 0°C -(the reference thermocouple does only a little better than this unless the 0°C offset voltage is very carefully tweaked - and remember that the literature indicates that we can expect up to about 1°C error due to instrument on-board cold junction compensation errors) - is likely because this particular thermistor only has a room temperature resistance tolerance of +/-5%. If measuring and then using the offset is not what you wish to do, you might have to buy one with a better tolerance and generally take extra-ordinary measures.

The DTS also showed an elevated temperature when in the ice bath - +2°C in this case. This time it is a little harder to understand, and because they are so new there is not much help out there on the web (and I doubt that the vendors have much real experience with them). With the software setting used it had a resolution of .25°C but this is user configurable (between 9 and 12 bits). In order to compare the response time of the two probes we can first immerse them in ice water then remove them and watch the temperature drift upwards towards room temperature - the results are shown in the figure on the right, and because of the construction method the sensor mass is very small compared to that of the probe. The two performed identically, but took ages to reach the new temperature - to get faster response you'll need to decrease the thermal mass of the whole probe significantly.

If we need to investigate the calibration over a narrower range we can play tricks like add ice to hot water and watch the temperature on both our Arduino output and our reference thermometer slowly drift up/down together - to see how your DIY measurements compare with the calibrated ones.


Making it cooler

The acrylic tube we used for waterproofing the sensors is a little on the large size, partly because of the large gauge lead wires used - you can customize your specific raw sensor so that it is encapsulated differently and suits your application more closely. You might want to skip the tube method altogether, just waterproofing the sensor alone with something like epoxy.


Geeking out

If you want to hack just a little more then you might choose to use a thermistor that you find out in the world, using obtainium can be particularly satisfying - such as from a BBQ probe or other similar digital thermometer. These will have a to-be-determined room temperature (25°C) resistance and materials constants, so you will need to measure the resistance at at least 3 different temperatures (some people ignore the "C" constant, so 3 might be enough) and solve the multiple equations to get the constant values. Luckily, websites exist to help you with this process.


Links

  • [1] thermistor description - suggested for beginners
  • [2] general thermistor reference
  • [3] description of the Steinhart-Hart equation, for thermistors
  • [4] assorted online calculators for thermistors