# LM34 and imp

I’d like some input on reading an analog device. I have an lm34 I’d like to read from. It provides a voltage on its output pin that varies with temp. If I configure an imp pin as ANALOG_IN, shouldn’t I be able to read it’s voltage?

Thanks.

Yep, you should. According to the datasheet it would appear that it’s 10mV per F, so I guess 70F would be 0.7V.

If that’s the case then using it is a two line operation:

hardware.pin1.configure(ANALOG_IN);
local temp_in_f = ((hardware.pin1.read()/65535.0)*hardware.voltage()) / 0.01;

…the second line works out the voltage of pin 1 (the ADC reads a fraction of the supply voltage, hence multiplying it by hardware.voltage()) and then sees how many F this is (at 10mV per F).

Is the Reference usd for the ADC the supply voltage itself, or was a real reference used on the imp ?
Otherwise, there’s no way to correctly measure the hardware voltage in absolute terms hence the above calculation can never be absolutely correct (only an estimation against the assumed hardware voltage.

The reference used for the ADC is the supply voltage itself. But there’s a real reference inside the imp, that it can use to determine the absolute value of the supply voltage, and hence the absolute value of an ADC input referenced against it. This is exposed to Squirrel as the hardware.voltage() call, which returns the actual supply voltage as a floating-point number of volts.

Peter

I’m looking at this LM34 part and it seems to need a 5V minimum power supply. How can the imp @ 3.3V supply that? Is the 10mV per F scaled for 5V and above, or it still holds true lower than that and as long as we scale with hardware.voltage() it will be correct?

the imp in any case doesn’t supply any voltage.

Assuming that you are using any of the available breakout boards or shields, you got an input voltage for the onboard regulator or anyway an alternative source of power that must be higher than 3.3V.

That’s the source for the LM34.

As I understand from the datasheet, the LM34 offers a calibrated output (10mV each F) independent of the input voltage. So the reference voltage is anyway unrelated to the source for the LM34 but is just a reference for the imp to properly calculate the read of the ADC.

The power supply of the LM34 and the imp are not related at all.

The problem it could be actually on the input of the imp, as the LM34 can output a value higher than what is acceptable from the imp itself.

According to the datasheet the maximum output voltage could be up to 6V.

Actually at 300F that’s the highest range the output should be 3,000mV (3V) that’s tollerated by the imp, but the max out of 6V is still there in the doc: