I know, this subject can be found all over the web, but the calculations sometimes are presented a bit cryptic as if the author wanted to put as many nested calculations on one line, so I just wanted to write something that explains it step by step, especially where the actual calculations are concerned. Lady Ada does a good job explaining the use of the thermistor, but I added some more explicit calculations. If the temperature goes down, the value of the resistor increases and so will the reading on the analog port. Suppose we have a 10k Seriesresistor and an NTC that for now we call ‘R’. Vo=R/(R+10K) * Vcc The analogPort readings however don’t give a voltage but an ADC value that can easily be calculated If we now combining the two formulas or as it is called ‘substitute’ Vo in the formula for ADC we get the following: This becomes subtraction of R Work -R into the multiplication As we are interested in R, divide both sides by the enclosed fracture The ’10’ stood for ’10k’ and as we don’t always use a 10k we just make it more general: So, as long as we know the value of the series resistor, we can calculate the value of the NTC from the measured ADC value. Now remember, this is valid voor a pull-up configuration. If it is a pull down configuration, the calculation of the ADC to resistor value is the inverse. Rntc = Rseries*(1023/ADC-1);// for pull down So what would that look like in a program? //Measure NTC valuebyte NTCPin = A0;const int SERIESRESISTOR = 10000;void setup(){ Serial.begin(9600);}void loop(){ float ADCvalue; float Resistance; ADCvalue = analogRead(NTCPin); Serial.print("Analoge "); Serial.print(ADCvalue); Serial.print(" = ");//convert value to resistance Resistance = (1023 / ADCvalue) - 1; Resistance = SERIESRESISTOR / Resistance; Serial.print(Resistance); Serial.println(" Ohm"); delay(1000);}//end program Knowing the resistance of the NTC is nice but it doesn’t tell us much about the temperature… or does it? However, there is a formula, the Steinhart-Hart equation, that does a good approximation of converting resistance values of an NTC to temperature. Its not as exact as the thermistor table ( after all it is an approximation) but its fairly accurate. The Steinhart-Hart equation looks like this: but fortunately there is a
simplification of this formula, called the B-parameter Equation. That one looks as follows: The program looks as follows: //---------------byte NTCPin = A0;#define SERIESRESISTOR 10000#define NOMINAL_RESISTANCE 10000#define NOMINAL_TEMPERATURE 25#define BCOEFFICIENT 3950void setup(){Serial.begin(9600);}void loop(){float ADCvalue;float Resistance;ADCvalue = analogRead(NTCPin);Serial.print("Analoge ");Serial.print(ADCvalue);Serial.print(" = ");//convert value to resistanceResistance = (1023 / ADCvalue) - 1;Resistance = SERIESRESISTOR / Resistance;Serial.print(Resistance);Serial.println(" Ohm");float steinhart;steinhart = Resistance / NOMINAL_RESISTANCE; // (R/Ro)steinhart = log(steinhart); // ln(R/Ro)steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)steinhart += 1.0 / (NOMINAL_TEMPERATURE + 273.15); // + (1/To)steinhart = 1.0 / steinhart; // Invertsteinhart -= 273.15; // convert to CSerial.print("TemperatureSerial.print(steinhart);Serial.println(" oC");delay(1000);}//------------- This ofcourse is not an ideal program. It is always good to take a few samples and to average them. float sample(byte z)/* This function will read the Pin 'z' 5 times and take an average. */{ byte i; float sval = 0; for (i = 0; i < 5; i++) { sval = sval + analogRead(z);// sensor on analog pin 'z' } sval = sval / 5.0; // average return sval;} Feedint the series resistor and NTC from the 5 Volt supply from the Arduino is possible. The Arduino power line does have glitches though. For accurate measurements it is better to use the 3.3Volt line as analog reference and feed the resistor from there. |