DS18b20 - multiple sensors, different readout increments

Hi,

I'm using 3 DS18B20 sensors coupled to the same pin (2) and using the OneWire library to read out the temperatures. It is used to measure the rising in temperature along 3 parts of a process (so they don't read out the same temperature at the same time).

The first sensor reads out with 0,01 degree increments, while the two other ones jump with 0,50 degrees.

I read in a previous post (here) that the sensors only have a 0,50 degree accuracy depending on the ammount of bits one is reading, but I didn't really understand what that meant.

In that same post it was also said that inserting a delay() might help... haven't tested that yet because I kinda want the temperature readouts at apporximately the same time.

I'm writing the data to an SD-card, as well as writing the temperature onto an LCD-display.

Here's the code I use (clipped out just the parts that concern the sensors

Initial code:

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

#define ONE_WIRE_BUS_PIN 2 // Pin for the temperature sensor
OneWire oneWire(ONE_WIRE_BUS_PIN);  // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);  // Pass oneWire reference to Dallas Temperature sensor

const int numSensors = 3; // Number of temperature sensors
float temperatures[numSensors]; // Array to hold temperature readings

code in void setup:

  sensors.begin(); // Initialize the DS18B20 sensors

Code in void loop:

        File dataFile = SD.open("datalog.txt", FILE_WRITE);

        dataFile.print(millis());
        dataFile.print("\t");
    
            for (int i = 0; i < 3; i=i+1) {
              // Read temperatures from all sensors
              sensors.requestTemperatures(); // Send the command to get temperatures
              temperatures[i] = sensors.getTempCByIndex(i); // Read temperature in Celsius
  
              //write teperatures to file
              dataFile.print(temperatures[i]);
              dataFile.print("\t");

            }
        dataFile.println();
        delay(1000); // Wait for a second before taking the next reading
        dataFile.close();

Here's a litte screenshot from the data (in excel).
Column 1 = time in minutes, Column 2 = sensor1, Column 3 = sensor 2, Column 4 = sensor 3
image

Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.