A thermistor is a resistor whose resistance varies with temperature. This is similar to the light sensor that varies resistance with light levels. The Arduino 101 Projects Kit has a MCP9700A Thermistor IC (Integrated Circuit) that contains signal-conditioning circuitry that outputs a voltage proportional to the change in temperature. This circuitry simplifies our task since we can use the Arduino ADC to measure the voltage and directly translate the reading to a temperature. The IC uses a T0-92 package as shown in Figure 4. Figure 5 shows a drawing from the data-sheet that illustrates the pin locations. Figure 6 has the breadboard and schematic symbols that we will use. This device measures in Celsius and its accuracy is +- 2° C from -40° C to 125° C. For those of us in America, we also translate Celsius to Fahrenheit in our Lab software using the following formula: °F = °C x 9/5 + 32.
Figure 4: Temperature sensor photo
Figure 5 - Temperature sensor datasheet drawing
Figure 6: Temperature sensor breadboard and schematic symbols
The MCP9700A outputs 10.0 mV/°C (10.0 millivolts [.01 volts] per degree Celsius) scaled for 500mV output at 0°C. Thus if we measure 500mV (0.5V) on the ADC, we know the sensor is detecting 0 °C. We can use this base point: 500mV for 0 °C to calculate the voltage for the maximum accurate temperature: 125 °C, and the minimum accurate temperature: -40 °C. Stop for a moment and think how you would do this. First look at the maximum accurate temperature: 125 °C. We know that we have 500 mV for 0 °C and that the sensor outputs 10 mV per °C. This means we have 10 mV per °C for 125 °C so we will see an additional 10*125 = 1250 mV above the mV level for 0 °C. So we add the mV at 0 °C, 500mv, to the 1250 mV for 125 °C and calculate that we would read 1750 mV as the voltage for our maximum accurate temperature reading. If this isn't clear then please write it out and do the calculations by hand so that you understand how to convert from volts to temperature.
Let's repeat this process to determine the voltage for the minimum accurate temperature, which is -40 °C. See if you can do this before reading further. We have a total of -40 °C, which would equal -400 mV change. Since we know that we would read 500 mV for 0 °C then we can subtract the 400 mV to get a -40 °C reading of 500 - 400 = 100 mV. We now know that if we read 100mV we have -40 °C, that if we read 500 mV we have 0 °C and that if we read 1750 mV we have 125 °C. Clear?
We saw in Chapters 6 and 7 that our ADC looks at voltages from 0 to 5 volts and divides that into 1024 steps with 0 being 0 volts and 1023 being 5 volts. We further saw that each ADC step represents 5/1024 = 0.00488 volts (4.88 mV). We know that the sensor outputs 10mV per °C, so how many steps in the ADC output would indicate 10mV? We see that the 10mV divided by 4.88 mV gives us 2.04918 steps, but the ADC steps are integers so we are going to have to do some math here. Two steps of the ADC (2 * 4.88mV) = 9.77 mV, so two steps are pretty close to a single °C change in temperature (10mV). Notice that the error between 10 and 9.77 is just under 1% and since the error for the sensor itself is 2% we might be safe ignoring the error and saying that two steps in the ADC output is equal to exactly 1 °C. Doing that would allow us to use integers rather than floating point data (data type that has integer and fractional parts divided by a decimal point) which use a lot more of the computer's resources to do calculations that when we use integers. Using the integer simplification would probably be good enough for most applications and would save us some serious computing. However, since we aren't doing a lot of extra work with this program, we will go ahead and write the code using floating-point data types. [To rephrase: in a more constrained program that does a lot of work and takes up a lot of space we probably wouldn't use floating-point, but accept the error and say that 2 ADC steps equals 1 °C.]
Or saying this another way, we know that the temperature sensor will output voltages between 100mV and 1750mV to indicate -40 °C to +125°C. The ADC outputs values from 0 to 1023 in steps representing 4.88mV per step. This tells us that the lowest valid ADC reading will be for 100mV giving us: 100mV/4.88mV/step = 20.49 step. But, of course, these steps are integers so we will say that the lowest valid step value is 21 which equals 21step * 4.88mV/step = 102.48 mV. We know that the temperature sensor outputs 100mV for -40 °C so 102.48 mV is slightly above that. We know that the sensor outputs 10 mV per °C, so we can calculate 2.48 mV / 10 mV/ °C = .248 °C giving us a temperature of - 40 °C + .248 °C = -39.75 °C. Of course our real accuracy isn't quite that good, but for our purposes here, we say that our systems lowest accurate temperature is -39.75 °C.
We can repeat this logic to calculate the highest accurate temperature reading: 1750 mV / 4.88 mV/step = 358.61 steps (359 steps since it is an integer) But when we calculate 359 step * 4.88 mV/step = 1751.92 mV we see that the 359 takes us above the highest accurate temperature output, that is 125 °C at 1750 mV, so lets drop the maximum step to 358 and we calculate 358 step * 4.88 mV/step = 1747.04 mV which is in range. We now see that the range of accurate readings from our ADC will be 21 to 358 out of a possible range for the ADC or 0 to 1023. For our purposes we should consider any ADC readings below 21 or above 358 as invalid and ignore them when we do our software conversions of the ADC readings to voltage and then °C.
Since this discussion is fairly complex, we will have a Lab to use all this in a test program to convert fake ADC readings to voltage and °C.