Need Help - Temp alarm project using LM35 and a potentiometer - Unstable temp

Am complete novice but I am working on a specific project and hit a wall. I need to build a temperature alarm with three settings for temperature threshold. Depending on which temperature setting threshold I select, an alarm (buzzer) would activate if the temperature falls below the threshold. I am using an Arduino Uno, a LM35 sensor and trying to use a simple potentiometer (B 50k-was in kit) to select the temperature threshold setting. To select one of three temperature settings, I divided the potentiometer reading as follows: < 340 - temp 1, > 340 && <= 680 - temp2, > 680 - temp3. I verify the potentiometer setting by lighting three LED's, 1 LED for temp1, 2 LED's for temp2 and 3 LED's for temp3.

On the serial monitor I print out the potentiometer reading, the LM35 reading in mV, and the temperature in C. Everything seems to work fine as far as the LED's coming on appropriately and the temperature reading seems reasonable (although consistently a couple of degrees lower than my room thermometer) and stable with the potentiometer set low around 0-100ish or so. But as I rotate the potentiometer the readings from the LM35 start to change, become wildly unstable and go way off base. For example, with the potentiometer set all the way to the right, the temperature reading climbs to over 120F and changes up and down significantly!

I have the potentiometer input set to the analog A0 pin. The LM35 input is set to the analog A1 pin.

I did not expect the LM35 reading to change at all when I rotate the potentiometer. I guess it changes the current flow in the circuit as the resistance changes but I wasn't expecting it to affect the output on the LM35 sensor. Not sure I understand the instability either.

Any help would be greatly appreciated. I hope I included enough information.

Thanks

We need to see your code to debug it.

What are those other components on the breadboard? Does it work when you remove them? Does it work when you remove the code for them and just trim it down to the minimum temperature+potentiometer code which exhibits the problem?

Thank you for the reply. The components are 3 LED's, 3 200 ohm resistors, 1 buzzer, 1 potentiometer and 1 LM35 sensor.

I've attached the code. I've tried to add enough comments to make it understandable.

I like the idea of using the potentiometer since it is easy change the temperature threshold settings and I can easily add additional intermediate threshold temperature settings as needed.

I haven't tried to unplug the buzzer and LED's to simplify things but can if need be. I just hate to redo the circuit unless it's the last hope to troubleshoot it.

Thanks so much for looking at it.

ps. I did remove the potentiometer and added two pushbutton mini switches just to see if it would work. It does but not preferable since it adds more connections and complications. I left the 3 LED's but only coded for 2 in this case. I am sending a pic of this arrangement.

TempAlarmLM35PotLED.ino (3.77 KB)

It takes some time for the ADC to "settle". There's only one shared ADC inside the ATmega chip and you may get some interaction between the two inputs you're using.

Try adding a delay (maybe one millisecond) before each analog read. Or, it seems to be common practice to take each reading twice and ignore the first reading (which takes much less than 1mS).

crojai:
...consistently a couple of degrees lower than my room thermometer...

Adjust the maths.

mV = (readTempValue / 1024.0) * 5000;

This assumes your 5volt rail is 5.000volt. It might be 5.094 volt.
Leo..

the lm35 can be unstable if you are using the computer usb to provide the voltage for the arduino as usb power is not very stable to begin with.

That, and an LM35 should always be read with the internal 1.1volt reference voltage.

The LM35 outputs only 10mV/degree C. The digital steps are too big (0.5C) with default Aref.
Leo..

Thanks for the inputs. This morning I set the aRef to 1.1v via analogReference(INTERNAL) and added a 10ms delay before the pot reading. Still having the same problem.

Any other suggestions would be appreciated.

Thanks.

I forgot to add the code file to my last message. See attached.

TempAlarmLM35PotLED.ino (3.98 KB)

Update: so this morning I tried a DHT22 sensor I had recently bought but had not tried yet. I downloaded the DHT22 library to my Arduino library folder. I modified the example code with my code for the potentiometer and LED's (no buzzer yet). I connected the data lead to pin 12 instead of analog pin A1 as I had for the LM35.

So when I ran the program the circuit performed flawlessly. Regardless of the potentiometer setting the temperature did not change.

I guess my followup question is this (being a novice might be a stupid question but I'm gonna risk it!). Does this mean that the LM35 is a analog sensor and the DHT22 a digital sensor? If so, is there an easy way to determine what a component is, analog or digital? What could I expect to happen if I plugged the LM35 data line to a digital pin versus analog pin?

Is my thinking right that because the DHT22 data line was pinned to a digital pin instead of the analog A1 that there is now no interference from the analog potentiometer? Is there such a thing as a digital potentiometer?

Thanks for your help. I'm trying to learn this stuff and your feedback is really helpful.

dht22 is neither a analog or digital. well not to the arduino anyway. The sensor does the reading then transfers the data back to the arduino by pulsing the input pin to represent data.

Without a pull down resistor on the analog pin, if the resistance gets too high, you could be getting noise.
I haven't used the DHT22 but I've used quite a few of the DHT-11's. The update time is a little slow but they perform rather well.

Nasa:
Without a pull down resistor on the analog pin, if the resistance gets too high, you could be getting noise.
I haven't used the DHT22 but I've used quite a few of the DHT-11's. The update time is a little slow but they perform rather well.

dht22 can be a pain.

if you ground the sensor to the arduino rather than a breadboard
add a capacitor across positive and negative to stabilize voltage
add a resistor as a pull up on the input pin
only read every second
don't read the first 2 seconds

then its a great sensor. Ive had them running for over 5 months and they still work great and are accurate.

gpop1:
add a capacitor across positive and negative to stabilize voltage

don't read the first 2 seconds

My votes for First and Second place.

add that cap and see if the issues reduce.

at minimal, read ADC line, twice, discard the first reading.