Multiple DS18B20 Temperature Sensors on one bus

terryking228:
Hi Everyone,

There is a lot around the web on this subject, but I have recently pulled a lot together and written clear example code. You can see the updated page on the http://ArduinoInfo.Info WIKI here:
http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20

I have a utility sketch that you can use to get the internal serial number (Device Address) on DS18B20's that you have. Then you can use those addresses in the code for multiple temperature sensors on one wire. This is important so you can know "which sensor is which" in a bus environment. You can see that info here:
http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#mult

I will have an example running in a day or two which displays and graphs inside and outside temperatures on KSduino.org

Hey,
Could you kindly help me to combine and develop a hybrid sketch that will contain both the utility sketch for internal serial number(Device Address) as well as sketch for reading the temperature from the above device addresses. I tried the above project but have been unsuccessful every time since there seems to b a problem in converting byte array into unsigned long integer (unint8_t). Recently, i tried converting it into a string and then to a unint8_t but didn't succeed.

Here's my code:

#include <OneWire.h>
#include <DallasTemperature.h>

// Setup a oneWire instance to communicate with any OneWire devices 
OneWire  ds(2);  // Data wire is plugged into pin 2 on the Arduino
DallasTemperature sensors(&ds);   // Pass our oneWire reference to Dallas Temperature.
DeviceAddress device;   // Assign the addresses of your 1-Wire temp sensors.
const char* newAddy;

void setup(void) 
{
  Serial.begin(9600);    // start serial port to show results
  sensors.begin();     // Initialize the Temperature measurement library
  sensors.setResolution(device, 10);     // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)zzz
  TemperatureAddress();
}

void TemperatureAddress(void) {
  int i;
  byte addr[8]; 
  int addx[8];
  
  
  Serial.println("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    String myString  = "";
     Serial.print("Address: ");                           //0x28, 0xFF, 0x1C, 0xB4, 0x54, 0x15, 0x03, 0x9E
                                                            //0x28, 0xFF, 0x4B, 0x85, 0x54, 0x15, 0x03, 0x9D

    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      myString+="0x";
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i]);
      addx[i]=addr[i];
      {
        
        
        String dig = "";
        int temp = addx[i] % 16;
        if (temp>9)
        {
          switch(temp)
          {
            case 10:
                dig+='A';
                break;
                
            case 11:
                dig+='B';
                break;
                
             case 12:
                dig+='C';
                break;
                
            case 13:
                dig+='D';
                break;
                
            case 14:
                dig+='E';
                break;

            case 15:
                dig+='F';
                break;
            }
        }
        else
        {
          dig+=temp;
          }

      temp=addx[i]/16;
        if (temp>9)
        {
          switch(temp)
          {
            case 10:
                myString+='A';
                break;
                
            case 11:
                myString+='B';
                break;
                
             case 12:
               myString+='C';
                break;
                
            case 13:
               myString+='D';
                break;
                
            case 14:
               myString+='E';
                break;

            case 15:
               myString+='F';
                break;
            }
        }
        else
        {
         myString+=temp;
          }     
        
        myString+=dig;
        
        }
      if (i < 7) {
        Serial.print(", ");
        myString+=", ";
      }
    }
    Serial.println();

    Serial.println(myString);
    
    
    const char* newAddy = myString.c_str();  
           DeviceAddress device =  { strtoul(newAddy, 0 ,16) };
    
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }

    sensors.requestTemperaturesByAddress(device);
           float tempC = sensors.getTempC(device);
           Serial.print("Temperature: ");
            if (tempC == -127.00) 
   {
   Serial.println("Error getting temperature  ");
   } 
   else
   {
    Serial.print("temperature in ");
   Serial.print("C: ");
  Serial.print(tempC);
   Serial.print(" F: ");
   Serial.println(DallasTemperature::toFahrenheit(tempC));
   } 
  }
  Serial.println();
  Serial.print("That's it.");
  ds.reset_search();
  return;
 }
   





void loop(void) {
  
  }

Any help is appreciated

You could start by seriously questioning why you would want to do that. You can use the sensors by the "by index" method which absolves you from finding the addresses, or you can find the addresses in advance and then include them in your programme. I would never use the former, but either method has to be a lot better than what you are doing.

Hi everybody,
I have a 1-wire network with 10 ds18b20 sensors for remote temperature monitoring of a thermal system. I use an Arduino Mega and a network shield for remote access. Results are displayed on an HD44780U LCD and on web browser. Everything has been working fine for the last two years.

Recently I decided to improve the system replacing the two line HD44780U LCD with a ILI9341 TFT screen, and I am experiencing an issue. The system works fine when I am in the test environment, with the sensors mounted on a breadboard, but when I move to the real environment the screen starts flickering and soon it gets dark.

The sensors network works fine with the HD44780U LCD version of the system. The maximum lenght of the bus is 20mt.
My guessing is that the bus drains too much power and the TFT screen does not work correctly because of that.

Has anybody got the same problem? any suggestion on how to fix it?

Thanks for your help

aldozan:
Hi everybody,
I have a 1-wire network with 10 ds18b20 sensors for remote temperature monitoring of a thermal system. I use an Arduino Mega and a network shield for remote access. Results are displayed on an HD44780U LCD and on web browser. Everything has been working fine for the last two years.

Recently I decided to improve the system replacing the two line HD44780U LCD with a ILI9341 TFT screen, and I am experiencing an issue. The system works fine when I am in the test environment, with the sensors mounted on a breadboard, but when I move to the real environment the screen starts flickering and soon it gets dark.

The sensors network works fine with the HD44780U LCD version of the system. The maximum lenght of the bus is 20mt.
My guessing is that the bus drains too much power and the TFT screen does not work correctly because of that.

Has anybody got the same problem? any suggestion on how to fix it?

Thanks for your help

Have you checked your power supply while the TFT is running?

Probably your PS is aging, what about replacing it temporarily with another and check the circuit behavior?

hi everyone

ı have one question for u... thank u for interest...
ı am making multiple DS18B20 temperature sensör devices so ı want to measure 10 temperature sensör and I want to choose the highest one how can ı make this?
thank u...

What do you mean with "the highest one"? Temperture or sensor ID?

in any case the solution is to compare each data in the row with the others, and take out the highest. With temperature is simple, with Sens ID a bit more complex but you can do it anyway!

Hi. I'm connecting two sets of multiple DS18B20 into one arduino Uno. So in my code how should i include them. I want the readings of a set of multiple DS18B20 separately and another set in separate.

sketch_nov20a.ino (1.5 KB)

You should have two different instances of the OneWire class on two different pins.

Have a look at the post from robtillaart Jun 07, 2014 just in this thread page 1.

Great work terryking228. One question for you or anyone with some insight on the matter. How would one use any one of the probes lets just say "Probe01" to control a relay when certain temps are hit for just that probe without the others interfering?
Thanks in advance.
Roger

if you put the sensors/temperatures in an array then it would become something like this (pseudo code)

for (int i= 0; i< 10; i++)
{
    temp[i] = sensor[i].getTemperatureC();
}

if (temp[5] > 25)
{
   relay[3].switchOn();
}
else
{
   relay[3].switchOn();
}

I'll be utilizing said sketch when I add a few to my fridge. There are always hot spots and colds spots.

Question on multiple digital sensors:
Can I use different pins instead of knowing the address or each sensor?

I want people to be able to plug sensors into connectors that equal what it goes to:

like this:

Connector - Item A Temp -- << -- If a sensor is connected it will show the temp of item A
Connector - Item B Temp -- << -- If a sensor is connected it will show the temp of item B
Connector - Item C Temp -- << -- If a sensor is connected it will show the temp of item C

All Temp sensors will have XLR connectors and can be plugged into any port...

Well, that is against the concept of bus itself!
Why don't you use difgerent kind of sensor, like a probe not connected to any bus?
Anyway if you really eant to use 1wire devices on different pins you should define multiple instamces of the 1wire class, each one connected to a different pin.

I can't see the point of what you are doing, but there is little point in questioning your motives - providing you know which sensor is which - as there are manifest benefits, even without using them on a bus. I think a better way of using DS18B20s on individual pins is here

This was a really helpful topic. When I went to it, I got the notice from wiki-spaces that they are closing down. I would hate for the community to lose this info. Where should it go to keep from losing it?

I guess you are accessing this forum through Wikispaces. I don't think the forum is closing, so access it directly.
http://forum.arduino.cc/index.php#c2

I know this is an old thread but I am having problems getting more than 4 sensors to work on a single bus. 4 sensors work fine. I add a fifth one and suddenly none of the sensors are visible. Doesn't matter which sensor as I have tried swapping in and out. As soon as I add the fifth sensor nothing shows up on the bus. Any thoughts?

Try using an external power supply, you may just be pulling too much power from the board.

I think it is just slack wiring. DS18B20s run on practically nothing and, if adding a fifth to a group of four was the straw that broke the camel's back, I'm sure we would all know about it.

Nick_Pyner:
I think it is just slack wiring. DS18B20s run on practically nothing and, if adding a fifth to a group of four was the straw that broke the camel's back, I'm sure we would all know about it.

I've wired it up 3 or 4 different ways on two different breadboards. Same result. Any 4 sensors works fine. Add any 5th sensor and they all disappear.