Go Down

Topic: DS18B20 Address Advice?? (Read 360 times) previous topic - next topic

lasersnake

I have a project where I am controlling the temperature of the fermentation of beer inside a fridge that has a heating circuit and a cooling circuit. I have 1x one wire DS18B20 sensor inside the beer which I use to control the heating and cooling and 1x one wire DS18B20 to measure air temp inside the chamber as a reference.

I would like to have this set up so I can interchange DS18B20 sensors without modifying the code( ie. not manually entering the sensor addresses in to the code). Currently both sensors are hooked up to the same pin on the Arduino but as there are only a couple of inputs and outputs on this project I can separate them to their own pins to make this easier.

Is there a way to either efficiently get the code to search for the address on a specific pin (that only has one sensor attached) and set that address to the sensor in the code

Or

Just not set the address for the probes as there is only one probe per pin. I have done this in a separate sketch as a test and have it working but I can not figure out how to set the resolution (which I want at 11) for the sensors. This would be my preferred method if possible to keep the code nice and lean.

Here is the test code I wrote;

Code: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_FRIDGE 5
#define ONE_WIRE_VAT 6

float air_temp;
float vat_temp;

OneWire oneWire_FRIDGE(ONE_WIRE_FRIDGE);
OneWire oneWire_VAT(ONE_WIRE_VAT);

DallasTemperature sensor_FRIDGE(&oneWire_FRIDGE);
DallasTemperature sensor_VAT(&oneWire_VAT);

void setup(){
    Serial.begin(9600);
   
    sensor_VAT.begin();
    sensor_FRIDGE.begin();
}

void loop(){
    sensor_VAT.requestTemperatures();
    sensor_FRIDGE.requestTemperatures();
    vat_temp = sensor_VAT.getTempCByIndex(0);
    air_temp = sensor_FRIDGE.getTempCByIndex(0);
   
    Serial.print("FRIDGE TEMP = ");
    Serial.println(air_temp);
    Serial.print("VAT TEMP = ");
    Serial.println(vat_temp);
  delay(1000);   
}


Any help would be greatly appreciated.

el_supremo

You don't need the addresses. Just do what you are doing in that code - sensors on separate pins and use getTempCByIndex(0). Resolution would be set with e.g. sensor_VAT.setResolution(11)

Pete
Don't send me technical questions via Private Message.

lasersnake

Thanks @el_supremo would the resolution setting line be in the set up or the loop or before the set up?

el_supremo

In setup() after the two .begin()

Pete
Don't send me technical questions via Private Message.

Go Up