Incorrect voltage readings from LM35 and STM32 (blue pill)

Hi everyone,

I am having trouble reading the analog voltage on pin A0 of a stm32 blue pill board. The voltage being read is the v_out of a LM35 temperature sensor.

The first voltage that is displayed seems to be correct (the temperature is around 20-21 degrees in this room, thus a voltage of 210 mV is expected), but every following reading seems 100 mV off.

The code being used:
#include “mbed.h”

//Virtual serial port over USB

static BufferedSerial pc(PA_2,PA_3,9600);

AnalogIn LM35(A0);

DigitalOut Led(PC_13);

FileHandle *mbed::mbed_override_console(int fd)

{

    return &pc;

}

int main()

{

   float value;

   float analogval;

   LM35.set_reference_voltage(3.3);

   printf("Starting temperature reading:?\r\n");

        

   while(1) {

        analogval = LM35.read_voltage();  

        value = analogval*3300/10;

        printf("Analogval: %d mV \r\n", int(analogval*1000));

        printf("Temp: %d degree C\r\n", int(floorf(value)));

        ThisThread::sleep_for(1s);

        Led =! Led;

    }

}

The readings from the serial port:
Starting temperature reading:?
Analogval: 211 mV
Temp: 69 degree C
Analogval: 91 mV
Temp: 30 degree C
Analogval: 96 mV
Temp: 31 degree C
Analogval: 99 mV
Temp: 32 degree C

I know that the conversion from volt to degrees is incorrect right now, but that is just a case of adding the right pre-multiplier. Also, I checked the voltage at vout with a multimeter and nothing seems wrong here (shows ~210 mV)

Does anyone have an idea what could be causing this behavior?

Best regards,

Yannick

I think I found the solution to the problem.

I added a 100nF capacitor and 1kohm resistor in series from the v_out to ground.

Now it displays the correct value in the serial monitor.

1 Like