
Using LM35 Temperature Sensor we display the Temperature on the LCD
After one week trying to read a temperature using stm32f103c8t6 and a LM35 I found that the only thing missed was a 10uF electrolitic capacitor between groung and signal pins of the sensor. Now it is working right.
main.cpp
- Committer:
- armo
- Date:
- 2020-07-12
- Revision:
- 1:9218b5180bd2
- Parent:
- 0:aed747a24dcd
File content as of revision 1:9218b5180bd2:
/**********************************************************************************************************/ /* ATTENTION: You have to put a 10uF electrolict capacitor between the ground and signal terminals of LM35*/ /**********************************************************************************************************/ #include "mbed.h" #include "TextLCD.h" AnalogIn LM35(PA_6); TextLCD lcd(PA_12,PA_11, PB_6, PB_5, PB_4, PB_3); Serial pc(PA_9, PA_10); //Create an object of Serial Class PA_9=RX, PA_10=TX no FTDI /*TextLCD lcd(p21,p22,p23,p24,p25,p26);*/ int main() { double tempC,tempF,avg;//,a[49]; int i; unsigned short a[99]; while(1) { avg=0; for(i=0;i<99 ;i++) { a[i]=LM35.read_u16(); wait(.02); } for(i=0;i<99;i++) { avg=avg+(a[i]/100); } tempC=(((avg*3.3)/65535)*100);//3.685503686 //tempF=(9.0*tempC)/5.0 + 32.0; lcd.locate(0,0); //lcd.printf(" Temperature "); lcd.locate(0,1); lcd.printf("%.2f \n %.0f",tempC,avg); pc.printf("%.2f \n\r",tempC);/*This line is to monitoring de temp values on a Terminal*/ wait(.5); } }