Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 1 month ago.
what coefficient value should be multiplied to get accurate LM35 reading
- include "mbed.h" DigitalOut green(LED_GREEN); DigitalOut blue(LED_BLUE);
AnalogIn T1(PTB2); temperature sensor T1 on A0 float T=0; average temperature float K=3.3*100; scaling coefficient for calculating analog value to temperature int main() { blue=0; blue=0; green=0; green=0; T= T1*K; average temperature value in Celsius (C)
Serial pc(USBTX,USBRX); pc.printf("LM35 temperature sensor\n"); wait(0.2f); wait a little pc.printf("Temperature (in Celsius) is %4.2f \r\n",T);
if ( T<=32) green=1; else blue=1; }
1 Answer
7 years, 1 month ago.
This seems to be a TI part, here is a datasheet:
http://www.ti.com/lit/ds/symlink/lm35.pdf
So the temperature in C is pegged directly to the voltage output of the sensor. Vout is independent of the supply voltage.
- 0V = 0C
- 1.0V = 100C
- 1.5V = 150C
- 3.3V = 330C
Let's assume the ADC on your board uses 3.3V for Vref+ and ground for Vref- (you should check this). The ADC read gives you a float value between 0 and 1 with 1 corresponding to 3.3V. So the scale factor of 330 looks right. Your program doesn't seem to have a loop. Maybe something more like this:
include "mbed.h" DigitalOut green(LED_GREEN); DigitalOut blue(LED_BLUE); AnalogIn T1(PTB2); //Temperature sensor T1 on A0 float T = 0; //average temperature const float K = 330; //scaling coefficient for calculating analog value to temperature Serial pc(USBTX, USBRX); int main() { blue = 0; green = 0; pc.printf("\r\nLM35 temperature sensor\r\n"); /* Loop */ while (true) { //average temperature value in Celsius (C) T = T1 * K; pc.printf("Temperature (in Celsius) is %4.2f \r\n", T); if (T <= 32) { green = 1; blue = 0; } else { green = 0; blue = 1; } //wait a little wait(0.2f); } }