# Expanding Range Of Analog Values From Temperature Sensor

I'm trying to build a temperature controlled relay module with an ATtiny45 ( Arduino UNO R3 as ISP ) and a NXP KTY81-222 Temperature Sensor.

The temperature range i want to monitor is 20°C to 30°C.

My circuit layout looks like this = ( I'm using the Arduino UNO R3 for debugging )

**notice that i've also tryed to "swap" the 1K resistor and the Sensor position to invert the output.

*and the arduino board ->

A0 is the Analog Input 0 of the Arduino. 5V is directly plugged into the 5V Output pin of the arduino.

( later it would be the same on the ATtiny45 using some batteries )

( VCC can be 2.7V to 5.5V )

I've used a household digital thermometer to compare the values from the analog input with the measured °C values.

this is a quick measure table =

Analog -> °C

687 to 690 -> 24.4°C to 25.1°C

707 to 708 -> 36.2°C to 36.5°C

as you can see i have a range from about 20 Analog units that represents a range from about 10°C units.

so what i actually want is to "grow" the range of the analog units to about 200 Analog units for 10°C units range. the solution should be a good to handle value range, so i can tell the µC to power the relay if temperature is under 24°C, and close the relay if the temperature is over 28°C.

I want 20°C to be an analog value from about 500 and 30°C to be about 700. ( this "range from 500 to 700 would be good enough for me.

i hope i could explain my question well for my bad englisch.

• Why do you want more precision? 0.5°C should be sufficient for this task. And don't trust a household thermometer too much. May 9, 2013 at 20:56
• i dont have any other thermometer to calculate the actual °C for each value. so why i want to have a bigger "range" is, that i need to figure out wich values to use in my code for the lower and the upper limit...
– Ace
May 9, 2013 at 21:25
• The real way to solve your problem of adjusting the range of your system such that the temp range of interest covers the range of your ADC is to use an operational amplifier circuit, removing the offset and increasing the gain. It's complicated a little bit by the fact that you have no negative power supply so you need to use single sided op amps. May 13, 2013 at 17:36
• hmm ok , i dont have any experience with amplifying :S i think i should just stay with the curent circuit, and try out with the given values. do you know any good method of "comparing" the analog values i get, to get the actual °C ? my room thermometer seems not to be valid.
– Ace
May 16, 2013 at 23:11

simulate this circuit – Schematic created using CircuitLab

You're going to run into some accuracy issues such as:

1. noise from the 5V line
2. self heating
3. possible voltage drop (due to length of wire)

I would just go with a one wire thermometer like the DS18B20/DS18S20. Using a digital sensor, less immune to noise. You can even run it at a much longer distance. There's a library for the Arduino already. Anyway, that's my route.

If you only want the temperature range from 20C to 30C, you're going to have to play around with your resistor to get that range. For example, at 20C the nominal resistance is 1922ohms and at 30C, 2080ohms.

So voltage divider states yields:

$$@20C: V_o = V_i\cdot\frac{R_s}{R_s+R1} = 5V\cdot\frac{1922}{1922+1000} = 3.288V$$

$$@30C: V_o = V_i\cdot\frac{R_s}{R_s+R1} = 5V\cdot\frac{2080}{2080+1000} = 3.376V$$

Difference is 0.08778V or 87.78mV. Since arduino's analog uses 10b (1023): $\frac{5V}{1023} = 4.888mV/\mathsf{step}$. This should have yielded 17.9 steps ($\frac{87.78mV}{4.888mV}$, so let's just say 17. If you want to bring this down to a larger resolution, you can connect the 3.3V from the Arduino's FTDI port to analog reference pin. However, power your voltage divider with the same 5V. In your void setup(), use analogReference(EXTERNAL). What this will do is set up your analog to use the 3.3V reference instead of 5V internal reference.

Now, let's do some more math:

Since we're using 3.3V reference now, the resolution changes to $\frac{3.3V}{1023} = 3.23mV/\mathsf{step}$. This will now yield 27.2 steps ($\frac{87.78mV}{3.23mV}$) (let's just say 27 steps).

As you can see, we're just improved from 17 steps to 27 steps. In a range of 10C (30C-20C), we can theoretically get a resolution of 10C/27 = 0.37C. I would recommend a capacitor in parallel with the sensor to create a first order low pass filter (allows low frequency through and rejects high frequency after cutoff at a rate of 20dB or 10 times rejection per decade). Wire this capacitor right between A0 and gnd (as close to A0 as possible). Cut off filter is calculated using:

Let's say you're using 1k resistor and 1uF capacitor:

$$f_c = \frac{1}{2\cdot\pi\cdot R\cdot C} = \frac{1}{2\cdot\pi\cdot1000\cdot0.000001} = 159Hz$$

All you have to do now is to play around with the resistor value (it should be bigger than 1k now). Make sure that the worse case scenario will not provide a voltage greater than reference voltage.

I would probably choose a 2k resistor:

$V_o = 5V\cdot\frac{1922}{1922 + 2000} = 2.450V$ so analogRead yields 759

$V_o = 5V\cdot\frac{2080}{2080 + 2000} = 2.549V$ so analogRead yields 790

Worse case scenario: @150C -> 4280ohms

$V_o = 5\cdot\frac{4280}{4280+2000} = 3.4V$ (ok)

Difference 98.73mV -> 98.73mV/3.23mV -> 30 steps

Low pass filter: $(2\cdot\pi\cdot2000\cdot0.000001)^{-1} = 79.6Hz$ (AC signal at 796Hz is reduced to 10 times smaller, at 7960Hz is 100 times smaller, etc).

• thank you for that good explaination. can you upload a quick drawing of the circuit layout for yout final solution please ? my electricl skills are not that good. also keep in mind ( for the self heating ) that i've the sensor on a 1 meter duplex wire. so it is out of the "electronical area". and also: can i simply use the 3.3V output pin of the arduino ?
– Ace
May 12, 2013 at 11:32
• i've updated my question with some reference pictures for the arduino and the attiny i'm using.
– Ace
May 12, 2013 at 19:56
• That 3.3V is output pin is coming from the FTDI chip. Remember that this pin can only handle up to 50mA. If you try to draw more than this, then it will fry the poor thing. Just use the picture that you currently have for the circuit layout. Place a ceramic capacitor between A0 and ground, so that it's in parallel with the sensor. I'm not sure how to upload pictures. May 13, 2013 at 16:28
• under yout answer text, you can click on "edit", in the editor you can klick on "image symbol" to upload an image to the text in current position. i dont know why i should use the capacitor, because i dont have ahy noise.
– Ace
May 16, 2013 at 23:07
• I'm pretty sure you will. For example, if you Serial print your analogRead(A0), the value will fluctuate even if the temperature is not changing. This is considered as noise. May 18, 2013 at 6:03

It may not seem a very wide range of digital numbers but have you considered avaeraging (say) ten readings. Noise (if generally above the bandwidth that you are needing to measure) can be used to your advantage by a process called dithering. In effect the randomness of the noise will give you a spread of readings for a fixed temperature and averaging several numbers will give your greater resolution. The act of averaging the numbers is a low-pass filter that (a) removes the noise and (b) gives you greater resolution.

You mention "analog units" but refer to digital values collected from an ADC so I'm proposing you do just this - at least try it and see what the variations are like. If you have really good stable signals into your ADC then some form of amplification can be tried using an op-amp. If you are decoupling the ADC's input with a capacitor then you might try removing it.

• i think the problem of the "noise" in my measure table above is my householt thermometer. i dont have any other instrument to measure correct temperature.
– Ace
May 12, 2013 at 11:42
• If you took ten or 16 or 32 readings in quick succession would all the readings be exactly the same? If yes then my answer won't help you. If there is a resonable spread of + or - one count change then my answer will help you. I'm trying to look for alternative ways that might help as opposed to the "standard" route of applying amplification. If you have a spare schmitt invertor you can superimpose the triangle waveform (much reduced in amplitude) to actually dither the signal slightly. The frequency needs to within nyquist and unrelated to your sampling frequency for it to work. May 12, 2013 at 14:04
• yes, while the wire with the sensor on it stays in my room, the value wont change, until i cool or heat the sensor.
– Ace
May 12, 2013 at 19:55