# How to connect two DS18B20 (Software) ArdBir v_2.6.70b



## Sergey (5/10/14)

I would like to connect two sensors (DS18D20) to measure temperature. One will participate directly in the process is an internal sensor, and the second will be just for informative. It will be installed near the pump. Is it possible to add a bit of code to achieve this task? I use ArdBir v_2.6.70b.


----------



## anthonyUK (6/10/14)

The DS18B20 is a 1-wire device which works on a bus system with every single device having a unique ID.
If you can read one it is simple to read an additional one or ten.


----------



## Sergey (6/10/14)

Yes. When I open the example code from the *File > Examples > OneWire > sample* menu I connect two sensors and I see the data from the two sensors. I'm trying to do the same in ArdBir. temperature is set 85 °C and not changed.

I'm sorry for my english.


----------



## mr_wibble (4/11/14)

Can you paste the piece of code in question?

It should be simple, but there's a couple of different ways to read these sensors. 
The most common (probably) way is to simply read them by "first", "second" etc.
The other way is to find the address of the device, and read from exactly that device.

Assuming you're using the Dallas library, the code is:

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

#define ONE_WIRE_BUS 9
OneWire one_wire(ONE_WIRE_BUS);
DallasTemperature sensors(&one_wire);

void setup()
{
sensors.begin();
}

void loop()
{
float temp1 = sensors.getTempCByIndex(0);
...
}


Adding another sensor should be as simple as just adding another line to the code:

void loop()
{
float temp1 = sensors.getTempCByIndex(0);
float temp2 = sensors.getTempCByIndex(1);
...
}
But you will have to test it to ensure the sensor you are reading is actually the first sensor. 

I'm not sure how the sensors are sorted on the one-wire bus, so when adding a new sensor it might become sensor0, and the original one pushed out to sensor1. You'll need to test.

If you can post the _relevant_ code section from your programme, I can take a look.


----------



## justsomeguy (6/11/14)

you should access the sensors by their address rather than by index. If one sensor fails for some reason you may read the sensor value at the first index and not realise that its actually the second sensor. The DS1820's have a burned in unique address so there is no chance of mixing them up.

I access the 3 on my system by address. It means I can immediately tell which sensor is unplugged when I start brewing.

Regards,
jsg


----------

