I am using 10 ds18b20 Temperature sensors using with "DS2482-100" I2C board and Arduino so when I am getting the output like this:- "ROM = 28 46 04 1F 0D 00 00 74 96014B467FFF0A100A 25.3 2699 Dc", so Instead of address I want to name it "Sensor-1", "Sensor-2" like that any tutorial or help would be appreciated.

  1. `* Arduino library for controlling DS2482-100 and DS2482-800 1-wire masters. Uses Wire library to communicate with DS2482 so be sure to call Wire.begin() before using the library. Quick example modeled after Onewire example: */

     #include <OneWire.h>
     #include <Wire.h>
     #include <DS2482.h>
     #include <DallasTemperature.h>
     DS2482 ds(0);  //channels ds2482-800 is 0 to 7, DS2482-100 is just set 0
     byte data[12]; //holding for onewire capture
     byte addr[8]; //1wire wire address and CRC
     long time_temp;
     uint8_t sensor1[8] = { 0x28, 0x00, 0xF9, 0x1E, 0x0D, 0x00, 0x00, 0x76 };
     uint8_t sensor3[8] = { 0x28, 0x61, 0x64, 0x12, 0x3F, 0xFD, 0x80, 0xC6 };
     void setup()
        pinMode(13, OUTPUT);
        // start serial port
         time_temp = millis();
     void loop()
       //do search
      if ( !ds.wireSearch(addr))
        if(addr == sensor1)
     Serial.print("No more addresses.\n");
    Serial.print("ROM =");
    for ( int i = 0; i < 8; i++) {
    Serial.write(' ');
    if (addr[i] < 16) Serial.print("0");
    Serial.print(addr[i], HEX);
    if (ds.crc8(addr, 7) != addr[7]) {
    Serial.println("CRC is not valid!");
    //test if device code DS18b20
     if (addr[0] == 0x28) {
     //read temperature data.
      ds.configure(0x05); //set bus on strong pull-up after next write until next command
      ds.wireWriteByte(0x44); //convert temperature on this device
      delay(770); //wait for conversion 750ms Plus margin
      ds.wireWriteByte(0xbe);         // Read Scratchpad command
      //display hex values of scratchpad
      Serial.print(" ");
      for ( int i = 0; i < 9; i++) 
       data[i] = ds.wireReadByte();
      if (data[i] < 16)Serial.print("0");
      Serial.print(data[i], HEX);
      Serial.print(" ");
      //convert to decimal temperature
        int LowByte = data[0];
        int HighByte = data[1];
        int TReading = (HighByte << 8) + LowByte;
        int SignBit = TReading & 0x8000;  // test most sig bit
        if (SignBit) // negative
        TReading = (TReading ^ 0xffff) + 1; // 2's comp
        int Tc_100 = (double)TReading * 0.0625 * 10;
        if (SignBit) // If its negative
        Tc_100 = 0 - Tc_100;
      //print temp for each device
       Serial.print(Tc_100 / 10);
       Serial.print(Tc_100 % 10);
       Serial.print(" ");
       Serial.print(millis() - time_temp);
       Serial.println(" Dc");
  • You've almost done it - but you can't compare one array to another as you would compare two ints. Instead you have to compare them byte by byte and test that both byte[0]s match, both byte[1]s match, ..., etc until you reach the end of the arrays. Some languages support comparing or doing arithmetic and array transformations on an entire array with a single statement. C++ doesn't support that.
    – JRobert
    May 21 at 15:43
  • 1
    Like JRobert said, it's not a feature of the language. It is, however, available to you in a couple of ways on the ESP8266. The C library (and therefore C++) has memcmp(), which will compare sequences of bytes. The ESP8266 also comes with a fairly complete C++ standard library, including std::equal, which can be used to compare arrays of anything that supports ==.
    – timemage
    May 21 at 17:17
  • Thanks a lot for the reply, I am trying it with 2 sensors,since I am new to this programming I am unable to write it correctly, and moreover I want to use it for 10 or more than 10 temperature sensors in that case is it possible to use memcmp(). Thank you
    – Khangesh
    May 26 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.