# How to write a formula for PIC16F in C to measure a sensor reading?

1. ## How to write a formula for PIC16F in C to measure a sensor reading?

how to write a formula to measure a sensor reading? for an example i want to measure temperature using LM35DZ ...newbie

•

2. ## Reading formula

For what processor, language?

•

3. ## Re: Reading formula

for PIC MCU 16F series using C language

•

4. ## Re: Reading formula

Originally Posted by blueroomelectronics
For what processor, language?
... and which compiler?

5. ## Re: Reading formula

Hi,
You use the formula as follows:

Sensor output in Volts(Vs) = ( N * Vref ÷ Nf) ÷ A

Where N = Current ADC Count
Vref = Vlaue of the reference Voltage in Volts ( 2V, 2.5V , 5V etc.)
Nf = ADC Full scale count (1023 for a 10 bit ADC, 255 for an 8Bit ADC etc.)
A = Amplifier Gain if used, else A = 1

Sensor Output as variable X = Vs÷ K, where K is the Conversion factor V/U(X),
U(X) is the unit of X

For LM35, K = 10 mV/°C = 0.01V/°C

So the current temperature measured Tc = Vs÷0.01 °C
= [( N * Vref ÷ Nf) ÷ A ]÷0.01 °C

Regards,
Laktronics

1 members found this post helpful.

6. ## Re: Reading formula

Laktronics , thanks...all the sensor reading can refer to your formula?

•

7. ## Reading formula

Looks right to me.

As a sidenote if you can convert the math to integer you won't need a floating point library.

--[[ ]]--