working on a project that involves monitoring temperature using an LM35 sensor with an STM32F4
Hello everyone,
I'm currently working on a project that involves monitoring temperature using an LM35 sensor with an STM32F4 microcontroller. I'm utilizing FreeRTOS for task scheduling and a CAN bus library for communication. However, I'm encountering issues with inaccurate temperature readings. The readings appear to be significantly different from expected values. Could you please assist me in identifying potential issues in my code and suggest corrections to ensure accurate temperature measurements?
Here's the relevant snippet from my sensor task implementation:
@Middleware & OS
Solution:Jump to solution
That's right , @Dtynin You need to take into account the reference voltage of your ADC and its resolution. For example, if you are using a 12-bit ADC with a reference voltage of 3.3V, the conversion should look something like this:
This ensures that the raw ADC value is properly converted to the voltage output by the LM35 and then to the corresponding temperature....
10 Replies
Your conversion seems to be almost too simplistic are you doing some preprocessing when reading?
Solution
That's right , @Dtynin You need to take into account the reference voltage of your ADC and its resolution. For example, if you are using a 12-bit ADC with a reference voltage of 3.3V, the conversion should look something like this:
This ensures that the raw ADC value is properly converted to the voltage output by the LM35 and then to the corresponding temperature.
Oh thanks, @Enthernet Code your detailed explanation on the conversion factor is very helpful. I will adjust the conversion to account for the reference voltage and ADC resolution.
In addition to what @Enthernet Code said, @Dtynin make sure your ADC is properly calibrated and configured. Secondly,curtail the noise in the power supply or grounding issues because it can equally affect the moneyreadings.Try as well to add a small capacitor (e.g., 0.1µF) close to the sensor can help stabilize the readings. I believe these points will be helpful to your project.
@UC GEE I'll check the calibration and configuration of my ADC and ensure proper grounding. Adding a capacitor for stabilization is a great idea. thanks
Where is the function to read temp sensor?
and also I think that it can be helpful by considering relationship between real temperature and capture adc value. currently it was assumed to linear relationship but I think that via several live experiments, we need to interpolate formula between adc value and real temperature.
There are several alternatives for temperature sensor and I think that it is not problem due to sensor.
when selecting any sensor, we have to consider its specification from datasheet and we need to preprocess and interpolate for sensor data. it is same case for LM35 too, I think.
Try initialize the ADC peripheral once ,and then put all the code to start the adc until get value in read_temperature_sensor().