Measuring temperature using analog temperature sensors (thermistors). Also, building a simple resistance measurement circuit (ohmmeter) using an Arduino (or just an ADC) and a resistor. This first part is mostly graphs and equations. If you don't care about the underlying math, you can skip to the next part. OverviewLet's start with the basics. You want to measure the temperature of a particular object, let's say the air's temperature right outside the window, using a microcontroller (e.g. an arduino). In general, there are two groups of temperature sensors that can do this for you: digital and analog. In this article, we will deal only with the analog kind. Using a microcontroller, in order to measure pretty much any analog physical quantity we must first convert it to voltage. This voltage we then feed into an analog input and we get a representative value. The thermistorNow let's examine a fairly simple temperature sensor, the thermistor. As the name implies, the thermistor behaves like a resistor, whose resistance varies depending on its temperature. In the case of the NTC (Negative Temperature Coefficient) thermistor, its resistance falls as its temperature rises. At a particular temperature, it exhibits a respective resistance. Therefore, by measuring its resistance, we can find its temperature. To do that, we need a mapping between the two. Thankfully, the behavior of thermistors is fairly easy to model. A simple lookup on Wikipedia provides us with the widely used beta-parameter equation: \( R = R_0 \cdot e^{-B (\frac{1}{T_0} - \frac{1}{T})} \) where \(R_0\) is the resistance at a temperature \(T_0\). This can be simplified to: \[ R = k \cdot e^\frac{B}{T} \label{1}\tag{1} \] where \( k = R_0 \cdot e^{ -\frac{B}{T_0} } \) is just a constant that depends on the actual thermistor. Note that \(T\) must be given in degrees Kelvin (\( T [°K] = T [°C] + 273.15 \)). The parameter \(B\), as well as the measurement set \((R_0, T_0)\) is usually provided by the manufacturer, but since these are hardly ever accurate (for low cost sensors), we will calculate \(B\) and \(k\) from actual measurements in the next post. Notice that the temperature \(T\) appears in the denominator. So, as the temperature increases, the resistance falls, which describes exactly what an NTC thermistor does. Of course, this is only correct because the parameter \(B\) is positive. Later in this article, we will solve the equation for \(T\), and make approximations to use in arduino code. Before doing that, however, we need to measure this resistance. Converting resistance to voltageThe analog inputs of our microcontroller measure voltage. To measure resistance, we will build a very simple voltage divider. The circuit is as follows: \( V_{cc} \) is the microcontroller's voltage. The voltage at the analog input (\(A_{in}\)) of the microcontroller is given by:
We will now try to find a good value for the series resistor \(a\). To do so, we make a graph of \( A_{in} \) versus temperature and observe how the curve changes based on \(a\). An excellent online graphing calculator I use for this part is Desmos. Here is a sample image, showing the thermistor's resistance versus its temperature: You can find the complete graph for this article here. Optimizing for a given rangeSo, let's now select a minimum and maximum temperature, for which we intend to maximize our sensor's resolution. As you can see from the graph and might have already guessed, this temperature range doesn't map to the entire (0% to 100%) range of the analog input. Thus, some of this \( A_{in} \) range is not used. To maximize the useful range, we need to maximize the difference \( A_{in}(T_{max}) - A_{in}(T_{min}) \). After differentiating and setting the derivative equal to 0, we find the optimal \(a\): \[ a_{optimal} = \sqrt{ R(T_{max}) \cdot R(T_{min})} \] Using this value for the in series resistor, we have the maximum analog input range, and thus resolution, for the given max and min temperatures. Finding the TemperatureNow that we have decided what value of \( a \) to use, one last question remains: How do we calculate the thermistor's temperature, given the value the ADC reads ? Using equations \ref{2} and \ref{1}, and after some algebra, we can find that: \[ T [°C] = \frac{B}{ \ln{a} - \ln{k} + \ln{\frac{100-A_{in}[\%]}{A_{in}[\%]}} } - 273.15 \] (I have left out the intermediate steps for clarity; if you prefer to see more detail, please let me know in the comments.) Of course, this equation, while mathematically correct, is not suitable to be used by a microcontroller just yet. In the next part, we will use an approximation of the above and an arduino to build the real thing!
0 Comments
Your comment will be posted after it is approved.
Leave a Reply. |
Categories |