You can see, that sometimes it reads the outside sensor instead of the inside. It never happens the other way.
I try it with it 2 seconds, but the result is the same.
Which Arduino board do you use ? How long are the wires ? Do you use two or three wires for the DS18B20 ? Can you give a full sketch that has the problem ?
If you bought your DS18B20 on Ebay/Amazon/AliExpress, then they are counterfeit. Those don't work well at 3.3V or at high or low temperatures or with long wires or with 2 wires to the DS18B20 (parasitic power).
The most common way it so get the temperatures every 2 seconds or every 5 seconds. Are you trying to get the temperatures every second ?
Sensors are in 3 wires mode, powered by 4.6V, wires are long about 70 cm. Arduino Nano, but this doesn't have any connection with the problem. The problem persists at both 1 and 2 seconds reading interval. It is present at 5 seconds too. Apparently it is not connected to measurement readiness, but with messing up addresses. It doesn't read wrong value, it reads correct value, but from the wrong sensor.
Of course anyone can ask anything. But I'm the one who decides to fulfill the request or no. Let's imagine that you are working on a commercial product and someone ask you for the whole code :). Or let imagine that you have thousands lines of code.
Or your experience is telling you that the asking person doesn't have enough experience and is asking unrelated things?
No, it is not commercial in my case, I'm just giving examples.
I think one of the the purposes of such forums is not to fix one (mine) problem, but to leave a trace for the problem, so others can find a solution without asking again.
I just cannot grasp why anyone would want to loose his time reading unrelated to the problem code.
My problem was illustrated by the title of the post. Then the code showed how I use the sensors, and this is the only code that has anything to do with these measurements. The log showed the results. I don't have a schematic, but I have described how the sensors are connected and powered. A just cannot give more meaningful information.
When such kind of question is asked I don't expect that someone will spend his time reading my whole code and looking my schematics. I expect that someone who had encountered similar problem in the past will see it and give some information.
This is not a rookie fix This is a fast and working fix. I have free pins, so for the moment it is easier, faster and safer to use another one than to spend hours trying to catch an elusive random problem, which could be caused by wire interference, a problem in the library or whatever other reason that is not caused by my code.
70cm is trivial wire length. 4K7 is the recommended pull-up for 5V operation. The library you used is a mystery since you didn’t include it in your code snippet.
Based on your description of your setup, the problem most likely resides in your code.
The library is the standard one that everyone is using for DS18B20. - DallasTemperature. It could be suggested from the snippets: DallasTemperature sensors(&oneWire); If not, you could ask about it without the need to post all the irrelevant code.
And If the problem is in my code, it should be visible, because the posted code snippet is all that is connected to the sensors.