1
\$\begingroup\$

I am a complete beginner in the field of electrical engineering. I have this temperature sensor with 2k Ohm resistance on 25°C. I have wired it parallel to a 3.6k Ohm resistor to lower the overall resistance, powered by the 5V output on my Arduino Duemilanove with ATmega168 chip. I connected this to an analog input channel.

My problem is how to translate the numbers I read from my analog input into temperature in °C.

My approach is the following:

  • 1/R = 1/\$R_1\$ + 1/\$R_2\$, so 1/R = 1/3600 \$\Omega\$ + 1/2000 \$\Omega\$, so R = 1286 \$\Omega\$.
  • R = U / I <=> R \$\times\$ I = U, hence 1286 \$\Omega\$ \$\times\$ I = U
  • Arduino analog input maps from 0V to 5V to 0..1023. Using this I can translate a given number into a voltage, and use the formula above (and a resistance table for that sensor) to calculate the currently measured temperature.

As you can see, I have not figured out yet what I would be in these calculations. Is my approach correct, and what is I in this context?

I would appreciate a hint in the right direction. Thanks in advance.

\$\endgroup\$
  • \$\begingroup\$ Kellen and I told in our answers that you don't want them in parallel. What gave you that idea to lower the overall resistance anyway? Just curious. \$\endgroup\$ – stevenvh May 28 '12 at 6:37
  • \$\begingroup\$ @stevenh I thought that if the resistance is too high I would not notice the change in voltage on my analog input. \$\endgroup\$ – nijansen May 28 '12 at 8:39
2
\$\begingroup\$

I think you are approaching this the wrong way. You shouldn't be placing the resistor in parallel, rather you should be placing it in series. If you place them in parallel, you will only ever read a fixed 5v on one side or 0v on the other. You will then use the ADC on the Arduino to measure the voltage between the temperature sensors and the resistor.

What you are doing is creating a where the resistance of the temperature sensor is changing.

The equation become non-linear, so if you would like to make it simpler you can combine series and parallel as explained in this answer.

\$\endgroup\$
  • \$\begingroup\$ That's a very helpful remark. But let's assume analogRead(sensorPin) gives me a value of 500 (so 2.44V). How can I calculate what the resistance of the temperature sensor is at that point? \$\endgroup\$ – nijansen May 27 '12 at 22:54
  • \$\begingroup\$ It become algebra at that point, based off of the voltage-divider equation. I have edited my answer with a link to another answer that gives a different method. \$\endgroup\$ – Kellenjb May 27 '12 at 22:55
  • \$\begingroup\$ Thanks, that answer is very interesting. I am looking into that. \$\endgroup\$ – nijansen May 27 '12 at 22:57
2
\$\begingroup\$

Like Kellen said, you should place them in series, not parallel.

enter image description here

The parallel resistors at the left both have the same voltage across them, that's the 5V from your Arduino. The fixed resistor has a fixed current, since the voltage is fixed as well, the thermistor's resistance varies, therefore so will the current. But the ADC in a microcontroller doesn't measure current, it measures voltage. And the only voltage this circuit has is the fixed power supply voltage, so you can't use that.

The two resistors in series at the right do the opposite. Since there's only one current path they both get the same current, and they may have different voltages across them. Say R1 is 15k\$\Omega\$ and R2 10k\$\Omega\$. Then the current it sees when you put 5V on it is 5V/(15k\$\Omega\$ + 10k\$\Omega\$) = 200\$\mu\$A. Then, according to Ohm's Law the voltage across R2 = I \$\times\$ R2 = 200\$\mu\$A \$\times\$ 10k\$\Omega\$ = 2V. You have a resistor divider which scales 5V down to 2V. More general:

\$ V_{R2} = \dfrac{R2}{R1+R2}\times V_+\$

If either R1 or R2 varies the output voltage will vary, and that's what we need. If you use a fixed resistor for R2 and let R1 be the thermistor, then a rise in temperature will cause R1 to lower, and the ratio R2/(R1+R2) will become larger; you'll have a larger output voltage at higher temperature. What will the temperature be? We can rewrite the resistor divider equation as

\$ R2 = \dfrac{V_{R2}}{V_+ - V_{R2}}\times R1\$

\$V_+\$ and \$R1\$ are known, the ADC measured \$V_{R2}\$, so we know the value of \$R2\$.

NTC thermistors have an ugly looking temperature characteristic. Datasheets for them may list a table indicating which temperature agrees with which resistance, so you could use that as a lookup table to find the temperature if you know the resistance. That's a perfectly good method, but it's a shame that we have to waste our microcontroller's memory on such a table.

In his answer Kellen links to another answer of mine, which shows how you can make the thermistor's curve more linear by using a parallel and a series resistance, so that the temperature can be approximated over a specific interval by the function

\$ T = a \times V_T + b \$

The coefficients depend on the type of thermistor, and the values of the two other resistors. In the linked answer I calculated them for another thermistor, based on a graph supplied by the manufacturer.

\$\endgroup\$
  • \$\begingroup\$ If I measure the value 740 from my analog input, and resistor R1 is 3,6k Ohm; 740 translates to 3.7V. Is R2 = (3.7V / (5V - 3.7V)) * 3600 Ohm correct? Because the result (around 10k Ohm) does not resemble a reasonable value. What did I do wrong here? \$\endgroup\$ – nijansen May 28 '12 at 9:29
  • \$\begingroup\$ @nijansen - 740/1024 * 5V = 3.61V (you probably thought the range was only to 1000). In the formula that gives 9k4. That's indeed too high. Do you have an Ohmmeter you can measure the NTC with? Are you sure about R1? Measure that as well. Measure the voltage on the ADC and see if it agrees with the 740. Report back. \$\endgroup\$ – stevenvh May 28 '12 at 9:39
  • \$\begingroup\$ The NTC measures out to 1.56k Ohm at the moment. R1 was wrong actually, it boils down to 4.52k Ohm (which would push the result in the wrong direction?!). The voltage on the ADC is in complete discrepancy however. It gives me between 740 and 750 from analog read, but I measured only 1.35V. How can that be? \$\endgroup\$ – nijansen May 28 '12 at 10:16
  • 1
    \$\begingroup\$ @nijansen - The resistor ratio agrees with the 740. I think you measured the 1.35V across the NTC, you should measure across the 4k52 resistor, and that should be the correct 3.7 V. \$\endgroup\$ – stevenvh May 28 '12 at 10:25
  • \$\begingroup\$ You are totally right. The voltage across the 4.52k resistor is 3.67V. Why was I not able to calculate the correct resistance of the NTC? Thank you so much for this comment walkthrough by the way. \$\endgroup\$ – nijansen May 28 '12 at 10:33
0
\$\begingroup\$

To keep self heating below 6mW absolute limit and minimise self heating error in degrees below 0.5 Kelvin keep current at 10% of max power. For 0.6mW, I=SQRT(P/R)=SQRT(0.0006/2000)=~0.5mA.

So the voltage must be about 1V. To scale the voltage to full ADC dynamic range you need a DC voltage amplifier stage which centers 1V nominal to 2.5V midpoint. Even more, you may want to reduce some classes of typical DC errors by using precision resistor bridge, instrumental amp, 4-wire cabling with drive-sense, shields, algorithmic filters. After this it only the interpolation formulas, linear or not, or table based, perhaps with calibration at sea level with boiling distilled water and water-ice mix.

\$\endgroup\$
0
\$\begingroup\$

http://hacking.majenko.co.uk/node/57 should help you find the exact voltage. Is says:

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println( readVcc(), DEC );
  delay(1000);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.