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:
void sensor_task(void *pvParameters) {
  while (1) {
    // Read temperature sensor data using ADC library function
    uint16_t raw_adc_data = read_temperature_sensor();

    // Convert raw ADC data to temperature value (assuming linear conversion for now)
    float temperature = raw_adc_data * 0.1;

    // Send the temperature data for processing and transmission
    send_temperature_data(temperature);

    // Delay task for a specific period
    vTaskDelay(pdMS_TO_TICKS(1000));
  }
}


@Middleware & OS
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:
float temperature = (raw_adc_data * 3.3 / 4096) * 100;

This ensures that the raw ADC value is properly converted to the voltage output by the LM35 and then to the corresponding temperature.
Was this page helpful?