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

Australia & New Zealand Homebrewing Forum

Help Support Australia & New Zealand Homebrewing Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

Sergey

New Member
Joined
4/10/14
Messages
2
Reaction score
0
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.
 
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.
 
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. :)
 
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.
 
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
 
Back
Top