LM35 Temperature sensor with STM32
LM35 is an integrated-circuit temperature device with an output voltage linearly proportional to the centigrade temperature. As LM35 is not calibrated in Kelvin, user does not require to subtract large constant voltage from the output to obtain convenient centigrade scaling.
Features of LM35
- Calibrate directly in Celsius
- 0.5°C Ensured Accuracy ( at 25°C)
- Rated for full -55°C to 150°C Range
- Suitable for Remote Applications
- Operates from 4V to 30V
- Less than 60μA current drain
- Low Self-Heating, 0.08°C in Still Air
- Non-Linearity Only ±¼°C Typical
- Low-Impedance Output, 0.1 Ω for 1-mA Load
- Power Supplies
- Battery Management
Click HERE to download LM35 datasheet.
We will use ADC to read values from LM35, And display it on the lcd. Lcd is connected via I2C using PCF8574. If you don’t know how to use DMA with ADC, check out this Tutorial. To know more about connecting LCD via I2C, go HERE.
Vcc is given to pin1, and pin3 is connected to the ground. Pin2 will be the input to the ADC pin of the microcontroller.
Create new project in CubeMx and select desired ADC channel.
Go to ADC1 config in configuration tab and make sure your settings are as follows
Go to DMA setting and select the following
That’s it for CubeMx setup. Generate the project and open it
Some Insight into the Code
uint32_t adc_buf is the ADC buffer, where values from LM35 will be stored.
int temp is the variable to store the temperature.
Write a Callback Function
Start ADC with DMA
Convert the temp (integer) to temperature (character)
send the temperature to the LCD
The following is the output in STMStudio. Variables observed are adc_buf and temp.
As you can see below the LCD showing temperature of the surrounding.
. . . . . DOWNLOAD . . . . .
You can buy me acontrollerstech
coffeeSensor by clicking DONATE OR Just click DOWNLOAD to download the code
- WavePlayer using STM32 Discovery January 16, 2021
- How to use SPI in LPC2148 December 26, 2020
- STM32 ADC MULTI CHANNEL WITHOUT DMA December 24, 2020
- Send and Receive data to PC without UART (STM32 USB COM) December 10, 2020
- STM32 GPIO INPUT Configuration December 4, 2020
- STM32 GPIO OUTPUT Config using REGISTERS November 24, 2020