how to compare two consecutive readings from ds18b20 sensor

I am having troubles on getting minimum and maximum readings from ds18b20. Basically I read two consecutive readings from sensor and compare two readings and calculate which is lowest and which one is highest in the loop().

here is sth like that.

void loop() {

float s2Now = sensors.getTempC(ProbeRoof);

s2Min = min(s2Now, s2Min); s2Max = max(s2Now, s2Max);


The problem is that I can get maximum reading correctly, the minimum reading is always zero. I might have to store the first reading somewhere for comparison but don't know how.

Create a new variable and copy the value to it.

You haven't posted all your code.

Clearly you've not initialized s2Min to a large value, which you have to do, and s2Max should be initialized to a large negative value.

If s2Min starts at zero it won't change till the actual temperature falls below zero.

Alternatively set both of s2Min and s2Max to the first reading you take in setup().