# Using an LM34 temp sensor, how can I limit the range of temperatures?

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?

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;

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!

• Oooh, I really like that idea, thanks. :) I've always had a problem converting the A to D data to decimal though. Which, by the way, I'm writing it all in Assembly (I've got a big project next semester for a class and it's all in Assembly, so I figure I'm better off getting some practice with this), so, while I understand the concept of what you're saying, how could I convert the A to D data into an actual decimal value? I know that's really a different question, but I figured I'd toss it out here. – Alex Kibler Nov 27 '12 at 19:46
• I can't give you all the secrets. :-) Seriously though, think about the steps one at a time. You're getting 10mV/degree from the sensor. You're ADC is 10 bits and 5V = 1024 counts. How many counts per mV? Now how many per 10mV? How many counts per degree? etc. – akohlsmith Nov 27 '12 at 19:50
• Haha, thanks. :) I just need to sit down and work it out. So it'd be 2 counts per 10mV, since it's 5mV resolution (almost), so 2 counts per degree Fahrenheit. I guess I don't even really need to convert it to decimal. I can just say if it's less than $whatever then turn the fan off, and if it's higher than$whatever, turn it on. My problem will lie in converting it to display on the LCD, but I can figure it out. Thanks! :) – Alex Kibler Nov 27 '12 at 19:54
• I have a quick question, though, if you wouldn't mind. I plugged the LM34 into the board and gave the top pin 5V, and the bottom pin ground, and the middle pin went to the ADC, so I could test if it was working. When I connect it all, the whole board shorts. Any idea why it would do that? The sensor is a resistor, so it shouldn't be getting infinite current, should it? – Alex Kibler Nov 28 '12 at 7:37

Instead of focusing on your sensor display range, why not focus on your control circuit. If you change the control to a proportional control, the fan speed will indicate air temperature and you can tell by the RPM of the noise.

The RED line shows your implementation. The others are hypothetical. The dotted line shows a possible non-linear control that may be adequate for your small space. The Green line, has 2 fans (200%) if you have additional capacity of thermal distribution or a CFM bigger fan.

I use my bios AMD quiet profile so my tower stays quiet until it starts to heat up and I can tell the CPU tmeperature if it gets above 70'C and how much just by the fan speed. Point being, I don't need to see the temperature sensor reading.