Electronic – Using an LM34 temp sensor, how can I limit the range of temperatures

fanmicrocontrollersensortemperature

Over the next two weeks, I'm going to be building a greenhouse fan system. It's not for a real greenhouse, though. It's just for fun. Anyway, my plan is to use the Dragon12+ board that I have, an LM34 temperature sensor, and a little 5V fan.

My goal is to read the temperature, convert it with the A to D converter, calculate the actual temperature from the values in the conversion registers, display it on the onboard LCD, and when the temperature reaches 85F, turn on the fan. Once the temperature gets back down to 80F, the fan would turn back off. So, really, the only temperatures I care about are from about 70-90F (Giving some extra room on both sides of the scale). How could I build a circuit to limit the temperatures that the sensor reads?

Would it be better to just implement it on the software side? My problem is that the A to D converter is 10 bits, so the resolution is (roughly) 5mV (5 volts over 1024 bits), and the sensor increases 10mV/degree. I know that it should be fine in theory, but will such a small step size of the sensor be a problem?

Best Answer

You don't limit what the sensor sees. The sensor reports what it sees. Your question is kind of like asking "I'm only interested in hot women. How can I adjust my eyes to not see ugly women?" You have no control over what the sensor sees.

Similarly, the ADC resolution (and sensor accuracy/resolution) will determine how fine-grained your temperature readings are, and how accurate they are. Generally this is never an issue unless you are specifically trying to save code or data space by looking only at 8 bits, for instance. Even in that case, you can always just read the upper 8 bits of the ADC (effectively making it an 8-bit ADC).

If you really feel you need to limit the range coming into the ADC, you can use an op-amp to shift and amplify the sensor signal so that 70-90 fits into 0-5 instead of the normal -55-150, but that's almost always not what you want to do because it's actually quite difficult to scale analog values without introducing noise or offsets.

It sounds like what you're after is something like this:

main_loop()
{
    while(1) {
        int temp;

        temp = read_temp();
        if (temp >= 85) {
            turn_fan_on();
        } else if (temp <= 80) {
            turn_fan_off();
        }
    };
}

You should add some code in there to only process that loop every second or so, and maybe check for out of range values to trigger an LED or something so you are informed when the sensor is detecting a bad condition. Maybe another check which reports a probable fan failure if the temp is above 95?

Sounds like a fun little project to get started with these concepts. Good luck!