Direct addressing temperaturesensors

The makers example program for reading DS18B20 sensors, starts with a search for the Rom of the different sensors, and after that, the program is asking each sensor in a fixed order to give the actual temperature.
This means that, if you change a sensor, the whole sequence is changed.
I’d like to change my program to read only the sensor I define with the known rom-adress.
I searched for hours (read days) without finding a solution.
Can somebody give me a sollution ?

If you are using the DS18B20 library:

Normally, when you use search(addr) it fills in an array of 8 bytes:

uint8_t  addr[8];

You don’t have to search for it, you can just statically define it:

uint8_t sensor1[8] = { 0x28, 0xdc, 0xbd, 0x48, 0x09, 0x00, 0x00, 0x76 };

And skip the search step and just look up that temperature using a specific address:

float tempC = getTemperature(sensor1);

thx for your answer. Sorry for this late reaction, but I wasn’t home for a couple of days.

Following your instructions, I added the Ds18B20 library. The Onewire library was maintained.
I also filled up a table with the ROm-adresses of the sensors. I put this table in the SETUP. Or is it better to insert in BEFORE the SETUP ?

I didn’t succeed to make the command "float TempC = getTemperature(sensor1) working : the getTemperature-command is refused as “is not declared in this scope”. Please can you explain how I can solve this problem ?

On beforehand THX for your appreciated help.

This should probably be ds18b20.getTemperature(sensor1); (where ds18b20 is the name of the object you created via DS18B20 ds18b20(pin, true);)


Sorry, yes there should be an object. I copied that code from a class that’s a subclass of DS18B20, so it didn’t need the DS18B20 object to reference the getTemperature method.

THX for your comments.
But I’m still in trouble : the command “ds18b20.getTemperature(sensor1)”; is not working. I wrote DS18B20 in capitals. This seems better, but now I get the message : “expected primary-expression before ‘.’ token.”

By trial and error I wrote some alternatives, but until now without a breaktrough.
Again, Can somebody help me ?

On beforehand THX !!!

Post your code then we can say more.

As asked for I’ll post my code.Maybe in a separate reply.

My aim is :

  • to read the nine sensors of my floor-heating system
  • print the results in the correct place on an LCD-screen 20x4
  • to count the number of Data-reading errors and to print that number to the LCD.
    -to calculate the % of false readings as a % of the total number of readings.
    (just to optimize the value of the resistors and optimize the wiring)

As the existing code reading the sensors in a fixed sequence is giving troubles I want to have a direct addressing of them. (in a lot of cases the actual search address routine is forgetting one of more sensors, so the search has to restart until the nine sensors are identified.This is not giving errors in the LCD-screen, but I would like to avoid that)
Here you have a picture of the LCD-screenI’llLCD%20temperatures%20and%20statistics The two upper lines are giving the temperatures (+1 figure on the right) and on the bottom of the screen you’ll find :

  • identifier of the currentsensor (0-8) being read
  • number of ROM-errors
  • number of data errors
  • total number of readings (up to 25.000 a day)
  • percentage of errors (1.75 % is a very bad day. Normally between 0.65 and 1.

I could not go further in the new .ino-file because the getTemperature command is refused

Remember, I’m not a professionnal…
THX and kind regards

I see I made a mistake in the program I was sending : the lines (for i=1 to 8…) for the reading of the HEX temperature data were canceled with //. Those lines have to stay activated of course.

I’m only looking for the correct environnement making the command “DS18B20.getTemperature(sensor1)” working. After that I can, by trial and error, continue to finalize the new program myself.


I see I don’t get answers on my question. Maybe the code wasn’t correctly shared.
So, I send that sharecode back.


Most likely. I can’t see it shared anywhere prior to your latest post.
When you post a link (which I can’t see anywhere) it would be good to immediately check that linke whether it’s working as expected or not.
You said

But obviously never did.

Also, what controller are you using?

With the DS18B20 library you wouldn’t need to include the OneWire library since the DS18B20 library already has the respective dependency set.

You are importing and including DS18B20 but why are you not actually using it?
Any previous response you got was given in the impression you are acctually using that library.

is this OK now ? ( I tested the link and it seems OK)
I was canceling the library OneWire, but still got the message : “not declared”

(SORRY for all the troubles !)

The link you posted before was OK too, but I said

The link in your (then) latest post wasn’t included in that statement :wink:

That’s no surprise since you are using OneWire instead of DS18B20, but why?
In your use-case you would use either one or the other.

@chip, try this. I haven’t got that many sensors to test, but this is how I’d do it (this should print the readings via USB Serial and publish to

THX for your help !

I copied the .ino file and the content was accepted : “Great Work !”.
Now I need a little bit more time to test the program WITH sensors and further adapt the program to my needs (with LCD and statistics.)

Again THANKS !

1 Like