How to use Temp Sensor (LM34) WITH LCD Keypad Shied

I need to rewrite my problem because I wasn't exactly stating my issue, rather how to program it..

Whenever I am using both the sensor and the shield (reading in analog values) the temperature sensor does not work properly because the buttons only work with:

analogReference(DEFAULT);

and the sensor needs

analogReference(INTERNAL);

One of the replies by lefty was kind of what I had but it still would not work.

It might work. One thing the datasheet warns when you change reference selection is to do a 'dummy' read as the first analogRead following a reference change is garbage. So try:

int getKey() {
   analogReference(DEFAULT);
   int temp = analogRead(BUTTON_PIN); // dummy read after changing reference
   return analogRead(BUTTON_PIN);
}

float getTemperature() {
  analogReference(INTERNAL);
  int temp = analogRead(TEMP_PIN); // dummy read after changing reference
  return (((5.0/9.0))*(((100.0 * analogRead(TEMP_PIN) * 1.084) / 1023)-32.0));
}

See if maybe that helps. Lefty

Hi Lefty,

The temperature sensor doesn't work with this approach. Any other ideas?

Any other ideas?

An op amp to boost the temperature sensor output to the DEFAULT range, instead of the INTERNAL range?

PaulS:

Any other ideas?

An op amp to boost the temperature sensor output to the DEFAULT range, instead of the INTERNAL range?

Why? I have a project that uses an LM34 and the INTERNAL reference. Works great without any amplification.

Why? I have a project that uses an LM34 and the INTERNAL reference. Works great without any amplification.

Are you also trying to read a device that operates in another range, as OP is doing?

Ok, I see that's how those buttons work. Pretty efficient use of a pin, didn't see that coming. I didn't look at the product sheet for the shield yet, but is it designed in such a way that the INTERNAL reference can't be used with it? You get so much more resolution by using the INTERNAL reference.

EDIT: Yeah, I found some schematics. They tied the top of the resistor stack to Vcc so the OP will have to use the 5V reference to read the buttons. Or maybe use the op-amp there to lower the voltage from the button stack and keep using the INTERNAL reference. I've always had poor results when I tried using op-amps with analog sensors like the LM34, but then I don't buy instrumentation amps and make boards to do it as a hobby.

afremont: They tied the top of the resistor stack to Vcc so the OP will have to use the 5V reference to read the buttons.

Pretty new to pcbs, how do I accomplish using a 5V reference to read buttons?

That would be the default reference, so just don't change it and it should be ok as far as I know.

afremont: That would be the default reference, so just don't change it and it should be ok as far as I know.

Then the temp sensor won't work.

critikull:

afremont: That would be the default reference, so just don't change it and it should be ok as far as I know.

Then the temp sensor won't work.

I don't understand why it wouldn't. You won't have as much resolution because of the higher Vref, but it should work just the same. You will have to adjust the math, but you shouldn't have any trouble resolving fractions of a single degree. You won't get tenths of a degree but you shouldn't have any trouble getting half degree resolution (or better) with the DEFAULT Vref of 5V.

That being said, there are ways to either, reduce the keypad output or multiply the voltage output of the LM34. Personally, I haven't had allot of luck when I dink with the output voltages of things like an LM34 because I always add noise. I'd prefer to move that noise to the keypad circuitry by dividing down the voltage output from the keypad to less than 1.1V max so that you can use the INTERNAL Vref.

That could probably be done by a resistor divider by using something like 4.7k of resistance to ground on the keypad output and 20k from there to the Arduino (looking for a 1:4 ratio). This is going to mean recalibrating your software to work with new values from the keypad as the original voltage ratios of the keypad resistor ladder will likely be lost by going thru the added resistor divider.

Another method is to use a voltage following op-amp that also divides down the keypad output. You should be able to tweak this to give you your original ADC scan values from the keypad, but using the INTERNAL Vref. This is because the original ratios should be maintained by the linear operation of the op-amp. I can help with this circuitry, but I'd like a little time to tinker on this end first to make sure I get it right. I'm just getting back into all this electronics stuff after a couple of years away from it. The circuitry wouldn't be complicated, just an 8-pin op-amp and a few resistors should do it.

The LM34 output pin should go to it’s own analog pin, it is capable of 10mA from the data sheet (attached) and thus might provide a load to interfere with the keypad.
To address another point the single bit value with an Accurate Vcc @ 5V is 4.88 mV ( 5.0/1024 = .00488V) or slightly less than 1/2 degree which agrees well with the stated and measured accuracy in this case .5 deg typ. measured and the the test limits for pass are +/- 2% of temp. It is my experience that the LM34 is an accurate standalone temp sensor that works well with the Arduino. I have used multple LM34’s through a CD4066 4 chan transmission gate and a 4051 for 8 channels and a 4097 for 16 inputs.
If in doubt about the source being driven by the LM34 a voltage follower works well but can shift the accuracy by the input offset voltage so a low Ios Op-Amp is required for best accuracy.

Bob

LM34XX.pdf (258 KB)