Store DS18B20 Onewire adresses in EEPROM

Hi all,

i have a project where a have a few DS18B20 temperature sensors (4 up to 12) on 3 busses ,
each bus having 4 sensors. I can read them , no problem. There are 4 sensors in each room
that i need to monitor, so it always comes in blocks of 4 (max 3 rooms)

But my question is , this project will need to be duplicated. I will provide the sensors with a tag
on each one stating his address. I have wrote a piece of windows software that communicates with
the arduino over Serial. Now i would want to have the user to be able to add or replace sensors by itself. I could do that by sending the address of each sensor over serial to the arduino from within the windows software. No problems so far.

My problem starts when the arduino recieves an event that he needs to write a new address for a certain sensor. I number the sensors 1,2,3 and 4 for the first room, 5,6,7,8 for the next and so on. There is some code here on the forum that lets you store the hex values of the address, but i can't get it to work. Does anyone have some advice on how to write such an address (array of 8) , read it on boot and set the addres of the onewire sensor?

that would be a life saver , thanks in advance.

Your post was MOVED to its current location as it is more suitable.

thanks, sorry for that mistake

What did you try and in what way did it not work?

one idea is a "read and store adresses"-function
it would work this way:
unplug all sensors and then just connect one sensor to make sure only one adress can be found.
Then press a button for "retrieve sensoradress" if sensor is found the user can choose which measuring-channel this is (1,2,3,4 or 5,6,7,8 etc.)
then press button to "store value (in EEPROM)"

It would be interesting to know what microcontroller you are using. If it is a ESP8266 or ESP32 you could work with a webinterface for this configuration.

Another approach would be to use the index-number of each onewire-sensor.
The library <DallasTemperature.h> provides functions to use an indexnumber for each sensor.
If in your application it is possible to warm-up each sensor easily from room-temperature to 30 degrees by taking the sensor between fingers the rising temperature could be used to identify which indexnumber is which sensor.

For simply storing the adress there is a datatype called device-adress

DeviceAddress myDemoAdress = {0x28, 0xB2, 0xCB, 0x5A, 0x08, 0x00, 0x00, 0xC3};

which is an array of byte with 8 elements

here is a short function that shows how to access each element of the adress-array and how to handover the 8 bytes as parameters

void Store8ByteAdress(uint8_t* deviceAddress, byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
   deviceAddress[0] = b0; deviceAddress[1] = b1; deviceAddress[2] = b2; deviceAddress[3] = b3;
   deviceAddress[4] = b4; deviceAddress[5] = b5; deviceAddress[6] = b6; deviceAddress[7] = b7;

In addition if you write more about your project I can bring in my creativity to suggest solutions
best regards Stefan

const int  EEaddr          = 0;     // EEPROM address for storing WPM
const int  EEaddr1         = 2;     // EEPROM address for LCD address
const byte ContrastPin     =  8;    // D8 low activates the Contrast adjustment

//in setup

    ReStart:  // Come back here if LCD contract is changed
    // Read the EEPROM to determine if display is using a custom contrast value
    NOKIAcontrast =;
    // Set the Nokia LCD Contrast to default or reset if EEPROM is corrupt or set to new value
    if (NOKIAcontrast  < 0xB0 || NOKIAcontrast > 0xBF) NOKIAcontrast = 0xB2;
    // LCD
    LcdInitialise();  LcdClear(); LcdString(*msg0);
    if (!digitalRead(ContrastPin)) {
        if (NOKIAcontrast > 0xBF) NOKIAcontrast = 0xB0;
        EEPROM.write(EEaddr1, NOKIAcontrast);
        goto ReStart;

// continue with setup

Now those cheak Nokia monochrome LCD are notorious for not having uniform contrast. The snip of code allows the user to press a recessed button to adjust the contrast for ambient temperature and display aging.

For 8-bit Arduino mini

here are some additional helper-functions that print "ready to copy & paste" lines of code with the onewire-adresses

#define NoOfoneWireDevices 20
// variable to hold device addresses
DeviceAddress DS18B20_Adress[NoOfoneWireDevices];
DeviceAddress DS18B20AdrList[NoOfoneWireDevices];

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

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

void printAddress(DeviceAddress deviceAddress) { 
  for (uint8_t i = 0; i < 8; i++)
    if (deviceAddress[i] < 0x10) 
    Serial.print(deviceAddress[i], HEX);
    if (i < 7) Serial.print(", ");

byte DS18B20DeviceCount;

void ScanOneWireAdresses() {
  // locate devices on the bus
  Serial.println("Locating devices...");
  Serial.print("Found ");
  DS18B20DeviceCount = DS18B20.getDeviceCount();
  Serial.print(DS18B20DeviceCount, DEC);
  Serial.println(" devices.");
  Serial.println("Printing addresses...");
  for (int i = 0;  i < DS18B20DeviceCount;  i++)
    Serial.print("uint8_t DS18B20Adr");
    Serial.print(i + 1);
    Serial.print("[8] = { ");
    DS18B20.getAddress(DS18B20AdrList[i], i); //that's the library-function to retrieve the adresses based on the index-number
    Serial.println("  };");

best regards Stefan

Thanks allot everyone for this input, i'm not at my programming computer now but i'll reply as soon as i am with code .