Temperature Sensor

Discussion in 'The Projects Forum' started by Dalaran, May 6, 2011.

  1. Dalaran

    Thread Starter Active Member

    Dec 3, 2009
    168
    0
    Can someone suggest a temperature sensor for a thermostat which would be for a fridge ~0C - 10C.

    I have the EasyPic6 development board and it comes with an onboard DS1820 digital temperature sensor, but I'm not sure I need something like this, and it seems a little complicated to use.

    Could I use a thermistor? This would seem like a much easier method to get it accomplished... but could it be accurate enough? Does anyone have part numbers they have used successfully in the past?

    Thanks!
     
  2. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Jameco pn 1871852 has worked well for me, but any 1 or 2% tolerance thermistor can be effective in the appropriate circuit. Vishay makes one very similar.
     
  3. ozmo

    New Member

    Dec 15, 2009
    10
    0
    I think because you have a relatively narrow temperature range you're looking to detect, won't need to be too picky about precision (0.5C precision will be probably be ok?), and won't be be running a lot of current through the thermistor, you have a very wide range of choices available to you.

    You can start with the Vishay NTCLE100E3103JB0 which covers the range -40C to 125C. Remember that thermistor resistance doesn't vary linearly and that you should make use of the Steinhart-Hart equation for best accuracy.
     
  4. Dalaran

    Thread Starter Active Member

    Dec 3, 2009
    168
    0
    Thanks very much for the replies. I don't see 0.5degree accuracy being a problem. Sounds like a thermistor is fine for my application. I will look into the part numbers provided.

    Thanks again for the guidance.
     
  5. wayneh

    Expert

    Sep 9, 2010
    12,127
    3,048
    Just for your own education, you might like to think about the widely-used LM35. This device produces a voltage output directly proportional to the temperature, 10mV/°C. So 0v at 0°C and 100mV at 10°C. It's more precise and accurate than a thermistor. Not necessarily any better for your application, but an option.
     
  6. Dalaran

    Thread Starter Active Member

    Dec 3, 2009
    168
    0
    Bringing back the older thread.

    I ended up going with the LM35 (thanks wayneh!) as it was all my local electronics store had in stock. I've used a PIC16F886 uC and put together a pretty basic thermostat, LCD temperature display and push button set point control. With the LM35 after ~3' of wire to get it in the fridge I see ~1degC variation in the temperature. I'm wondering if this would be expected from this device.

    I am using a reference voltage of ~400mV instead of the 5V supply to increase my accuracy. What can I do to increase the precision of this? Would a small cap to ground on the sensor analogue output help to stablize the measurement? Should I just go to a thermister as this should probably be more stable?

    Any thoughts welcome!
     
  7. #12

    Expert

    Nov 30, 2010
    16,298
    6,811
    The datasheet on the LM35 says it is good to +/- 1C. The refirgerator isn't that stable. Which are you asking about?
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,605
    Well the first thing to try is to isolate the sensor is a stable temperature controlled environment of a well defined temperature. That way you can be sure that any variation is due to electrical noise.

    So take the sensor and dunk it into a glass of ice water. As long as you still have ice you have a zero degree C environment.
     
  9. Dalaran

    Thread Starter Active Member

    Dec 3, 2009
    168
    0
    Thanks for the replies.

    Sorry, to be more clear, its not whether the sensor is accurate to the abmient temperature, but in a stable environment my reading varies about 1degC. I am wondering how to stablize this voltage or whether it seems reasonable?

    Cheers.
     
  10. #12

    Expert

    Nov 30, 2010
    16,298
    6,811
    Does it vary by 1C in a matter of seconds? overnight?
     
  11. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Dalaran, take a number of readings over one mains cycle, then average them. It's most likely your ADC is being affected by some few mV of mains hum being picked up on the sensor lead or PIC PSU etc.

    If your mains is 60Hz then sample 10 times, at 600 times per second (1667uS period) which gives you 10 ADC readings over 1 mains cycle.

    Then just add those 10 readings and divide by 10. You should then have a temperature reading with better stability than 1'C.
     
  12. Dalaran

    Thread Starter Active Member

    Dec 3, 2009
    168
    0
    Thanks for the replies.

    I am averaging my ADC measurement over 50 readings. I increased the delay before taking the ADC measurement to ensure it had ample time to charge (from 50us to 2ms). Increasing the delay seemed to help stablize my measurement some. Would it make more sense to do 10 readings over 1 mains cycle or is what I am doing sufficient? What is the benefit to doing it over 1 mains cycle as opposed to an arbitrary time?

    I also added a 10uF capacitor from the sensor signal pin to ground near the uC. A smaller cap (100nF) seemed to make this worse but the 10uF seemed to help quite nicely. I am now down to a variation of ~0.3-0.4degC. This seems more reasonable to me. This variation is in a short period of time; after a couple times of running through the code (>1s).

    Thanks again all.
     
  13. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    The sensor makes 10mV 'C, so a few mV of mains hum will affect it, depending when you take the ADC sample.

    The reaons for averaging over one (or more) FULL mains cycles is that the hum will be evenly distributed with half the samples being high from noise and half being low from noise. If you sample at an unknown period you risk that there will be beat frequency and many of your ADC samples will coincide with the instant when the mains hum is high, or low etc.

    With a 10uF cap on the ADC pin you can run a series resistor say 4k7 between sensor and the ADC pin. That will give you further hum rejection.

    Then since you already have code to average a large number of readings (you said 50) then just take 50 (or 1000 or whatever) over a long time period with ADC periods evenly divisible by the mains period.

    As an example you could take 1000 readings with exactly 4 readings per full mains cycle. ie 1/60/4 = 4.167mS per ADC period, total time to add 1000 readings is 4.167 seconds.

    Since you are using the compiler it's trivial to average 1000 10bit ADC readings by just adding the values in a unsigned long variable, then do /1000 at the end. Of course if you average 1024 readings you can do /1024 at the end which is much faster.

    I have a few commercial room temperature sensors and they all sample over a 10 second period and update the display every 10 seconds.
     
  14. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,605
    When all else fails, read the find manual (RTFM).
    With a series resistor at the device you get a natural roll-off with the cable capacitance, then you can add some more at the controller side.

    10 uF is a lot of capacitance (but might have been picked via "spare parts in my box" which is an acceptable criteria). I would wonder what reference the controller's A2D is using. If it's just the power supply the best put lots of cap on that too. If you have a 3 terminal reference did you catch the part in it's spec where it says put 1uF of cap on it as a minimum?
     
  15. wayneh

    Expert

    Sep 9, 2010
    12,127
    3,048
    Just for grins watch the voltage from the LM35 with a DMM. You'll see a rock solid reading, with the little bit of integration provided by the meter. I'm saying the issue is the ADC. I suppose you knew that from the previous posts, but double-checking with the meter can help rule out other things. I use lightly shielded wire for my LM35 applications. It's old airline-free-headphone cable.

    Working in the mV range, I had a lot of trouble with ground not really being ground. Make sure that wires to your reference ground don't carry any significant current. And check voltages everywhere in your circuit, to verify that what you think is "0", is actually less than a millivolt or so.
     
  16. Kingsparks

    Member

    May 17, 2011
    118
    5
    Hi.
    I don't know if it would make any difference in this application but we used to get a lot of hum on intercom systems installed by other parties. Almost every time it was the use of phone wire, or sometimes doorbell wire, not dedicated intercom wire. Point is, phone wire has something like two or three twist per inch and that was not enough for common mode rejection. Changing to dedicated intercom wire cleared it up.

    I had occasion to use some phone wire once, only choice at the time, but by stripping it out of the main outer insulation and taking the individual pairs, with a drill I increased the twist to about five per inch and it worked just fine. Would perhaps twisting the 3' wire connected to the sensor help with AC rejection, if that is an issue? Or is that so obvious it was already done.
     
  17. Dalaran

    Thread Starter Active Member

    Dec 3, 2009
    168
    0
    Again, everyone, I appreciated the replies.

    As per recommendations I am going to do the following things to hopefully improve the stability of the reading even further:

    1. Add ~4k7 resistor in series with sensor signal pin and uC ADC (edit: after re-reading posts above I think I will try adding a 2k resistor to both sides of the LM35 signal wire).
    2. Average ADC reading over a certain number of complete mains cycles and probably increase the update time (at a few times a second now which isn't necessary).
    3. Add at least 1uF capacitor to the Vref+ pin used for the ADC reference voltage (currently just a 10k/1k voltage divider giving ~450mV for increased range on the ADC).
    4. Add shielded cable if the I can find some readily available.

    Thanks!
     
    Last edited: Jun 2, 2011
  18. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Just for comparison to your LM35 results, I have a comparator circuit that uses a thermistor as its sensor and it is repeatable to +/- .2°F in the range from 85°F to 105°F. I am not saying that thermistors are better than the LM35/LM34, but in some situations, they produce really good results. I think some people write thermistors off too quickly because they are low tech.
     
  19. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Aha! There's a big part of your problem. In the PIC datasheet it says the ADC has a minimum recommended Vref of 2v. Less than that will cause an unstable reading.

    Also if you are using EasyPIC6 dev board on USB power, please check your USB 5v, you will find it probably varies up or down 20mV or worse as your PC does different tasks.

    Since your Vref is Vdd derived it contains all Vdd error, although reduced by the voltage divider.

    Try using a 1.8v LED and resistor as the Vref, this still gives you a few ADC counts per 'C and will remain quite stable at voltage even while Vdd fluctuates 20mV. :)
     
  20. Dalaran

    Thread Starter Active Member

    Dec 3, 2009
    168
    0
    Aha! Thanks again for the replies RB. In the ambient room I am currently only fluctuating 0.1 degC and 0.2degC in the fridge using the previous set of suggestions (thanks everyone!). But maybe using the lower Vref is killing my accuracy although doesn't seem to be hurting my precision. Even if I use exactly 2V reference I still only have 1 ADC count / ~0.2degC. Not exactly what I was hoping for but will have to do.

    I like the idea of using an LED as the voltage drop across it will always be constant. I'll have to check the forward voltage on the LED stash I have at home. Otherwise the voltage divider seems to be working well so far.

    Cheers!
     
Loading...