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.
- Interface WS2812 with STM32 April 16, 2021
- PWM with DMA in STM32 April 8, 2021
- Control Stepper motor using Rotary Angle Sensor March 21, 2021
- External Interrupt using Registers March 17, 2021
- STM32F103 Clock Setup using Registers March 3, 2021
- STM32 I2C Configuration using Registers February 26, 2021