Multiple DS18B20 discovering question

Hi everyone.
I’ve got multiple DS18B20 sensors with read and known addresses. Is it possible to assign names to those addresses and use them to print my temperatures with the names, not the addresses. I mean, I’ve got database with declared addresses in my code of multiple DS18B20 sensors, function searches thru them and prints in serial only those sensor’s names and their temperature values, which are discovered.

In earlier post someone suggested this code(“tester” code in DallasTemperature.h examples):

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 10 // Lower resolution

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

int numberOfDevices; // Number of temperature devices found

DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address

void setup(void)
  // start serial port
  // Grab a count of devices on the wire
  numberOfDevices = sensors.getDeviceCount();
  // locate devices on the bus
  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.println(" devices.");
  // Loop through each device, print out address
  for(int i=0;i<numberOfDevices; i++)
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
		Serial.print("Found device ");
		Serial.print(i, DEC);
		Serial.print(" with address: ");
		Serial.print("Setting resolution to ");
		// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
		sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
		Serial.print("Resolution actually set to: ");
		Serial.print(sensors.getResolution(tempDeviceAddress), DEC); 
		Serial.print("Found ghost device at ");
		Serial.print(i, DEC);
		Serial.print(" but could not detect address. Check power and cabling");


// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
  // method 2 - faster
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");

void loop(void)
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  // Loop through each device, print out temperature data
  for(int i=0;i<numberOfDevices; i++)
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
		// Output the device ID
		Serial.print("Temperature for device: ");
		// It responds almost immediately. Let's print out the data
		printTemperature(tempDeviceAddress); // Use a simple function to print out the data
	//else ghost device! Check your power requirements and cabling

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
  for (uint8_t i = 0; i < 8; i++)
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);

It discovers my multiple sensors but the names are “device0, device1”. I would like the output to be like I declare my multiple sensors addresses before setup and function discovers which of declared sensors are connected and prints temperature values in serial only for those.

Any simple examples or explanations?
Maybe bool function could do this but I actually don’t know how and where to use it.

Thanks for any help.

You can access the device address, which is an 8-byte array.

The function printAddress() prints this out and could be modified to substitute meaningful names for the addresses already discovered.

i could read my device's addresses manually, they are known. want to declare them before setup and assign names for them, but I do not understand how to write the function, which detects what of my declared sensors are connected.

I can assign the names like:

uint8_t sensor1[8] = {0x28, 0xFF, 0x6B, 0xD3, 0x43, 0x16, 0x03, 0xD1};
uint8_t sensor2[8] = {0x28, 0xFF, 0x3C, 0x05, 0x44, 0x16, 0x03, 0x67};]

but what to do next with them? :o

You could use a two dimensional array to define two or more sensors, e.g.

uint8_t sensor[8][2] = {0x28, 0xFF, 0x6B, 0xD3, 0x43, 0x16, 0x03, 0xD1,
                        0x28, 0xFF, 0x3C, 0x05, 0x44, 0x16, 0x03, 0x67};

and address each one by index (in the above case, 0 or 1):

int i=1;
sensors.setResolution((DeviceAddress) &sensor[0][i], TEMPERATURE_PRECISION); //ith sensor

I don't know if the cast is necessary, but the "&" address operator will be.

Of course, you have to know which sensor is which and to do that, you might need to detect and save the contents of the 8 byte ID array somewhere.

I believe you can also define an array of device addresses thusly:

DeviceAddress sensors[3];

Copy the bytes from one to another using memcpy:

DeviceAddress temp;
DeviceAddress sensors[3];


I'm not ignoring last post, it just takes time for me to understand and learn what's explaining as I'm so new to arduino and it's language. Thanks for now!