Multiple DS18b20 Long-Distance Sensors Returning Error

Hey All,

I recently started updating a wired sensor network I had that would values from different fish tanks and broadcast them to be read off a serial port by Putty. For this project, I had an Uno and a Teensy 3.1. Both had multiple DS18b20 sensors attached, and had a relatively low rate of errors (<5%).

As part of my summer internship, I learned how to use the data visualization suite ELK (ElasticSearch, Logstash and Kibana), and wanted to start using them for my project.

I now have four Unos (Two with two DS18b20s, one with one, and one with a DHT11). Each one has an nrf24L01 2.4Ghz receiver (and those all seem to work fine).

The DS18b20's are sending me back an error of "185.00F" (85C). When I unplug either the power or ground, I get "-196.60F" (I expected this). I have checked my wiring and connections, and they appear to be in the exact same places as the old system. I am also using the same sensors & long-distance wires (the longest is maybe 18 feet long).

Here's a sample sketch (each Unp + DS18b20 runs a slightly modified version of this):

//Packet Two - Waterproof Sensors
#include <DallasTemperature.h>
#include <OneWire.h>

//Need for both. These are the radio libraries:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

//If using the DS18b20 (OneWire) protocol, include the following. If using the DHT protocol, delete the following:

//Data wire is plugged into pin 7 on the Arduino
#define ONE_WIRE_BUS 7

//Setup a oneWire instance to communicate with any OneWire devices including non-IC/Dallas Temperature ones 
OneWire oneWire(ONE_WIRE_BUS);

//Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//Temperature Variable
float TempF0, TempF1;

//For nrf24 debugging
int serial_putc( char c, FILE * )
{
  Serial.write( c );
  return c;
}

//More nrf24 debugging
void printf_begin(void)
{
  fdevopen( &serial_putc, 0);
}

//Pins the nrf24 will use to transmit and recieve data
RF24 radio(9,10);

//Only need a "write" pipe ATM, but will use it later
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL,0xF0F0F0F0D2LL};

//Can send up to 30 characters here:
char SendPayload[31] = ""; //What does this do?



void setup() {
 //ONEWIRE ONLY:
 pinMode(ONE_WIRE_BUS, INPUT);
 
 //Start the serial
 Serial.begin(57600);
 Serial.println("Printing Tranmissions to Serial:");
 printf_begin(); //What does this do?
 
 //nRF24 configurations. Make sure they are the same on here and the Pi
 radio.begin();
 radio.setChannel(0x4c);
 radio.setAutoAck(1); //What is AutoAck?
 radio.setRetries(15,15); //What does this do? What does the (15,15) mean?
 radio.setDataRate(RF24_250KBPS);
 radio.setPayloadSize(32); //Is this 32 bits or 32 bytes?
 radio.openReadingPipe(1,pipes[0]);
 radio.openWritingPipe(pipes[1]);
 radio.startListening();
 radio.printDetails(); //For debugging
 
 //For DS18b20 (OneWire) only:
 sensors.begin();
}



void loop() {
  therm0();
  
  //Wait 30 seconds
  delay(30000);
  
  therm1();
  
  //Wait 30 seconds
  delay(30000);
}



void therm0(){
  if (sensors.getTempFByIndex(0) == 196.00){
    TempF0 = TempF0;
    Serial.print("POWER ERROR! SENDING OLD VALUE!");
  }
  else if (sensors.getTempFByIndex(0) == 196.60){
    TempF0 = TempF0;
    Serial.print("POWER ERROR! SENDING OLD VALUE!");
  }
  else if (sensors.getTempFByIndex(0) == 32.00){
    TempF0 = TempF0;
    Serial.print("CODE ERROR! SENDING OLD VALUE!");
  }
  else if (sensors.getTempFByIndex(0) == 185.00){
    TempF0 = TempF0;
    Serial.print("WIRING ERROR! SENDING OLD VALUE!");
  }
  else{
    TempF0 = sensors.getTempFByIndex(0);
  }
  
  //Asign TempF0 to payload, sending it as a string:
  dtostrf(TempF0,2,2,SendPayload);
  
  //Change the number after the "T" for eaach sensor. Follow the Numbering System.
  strcat(SendPayload, "-T00"); //Tags to help sort the data (Value, Sensor)
  
  //Send a heartbeat
  radio.stopListening();
  bool ok = radio.write(&SendPayload,strlen(SendPayload));
  Serial.print("");
  Serial.print("Sending: ");
  Serial.println(SendPayload);
  radio.startListening();
}



void therm1(){
    if (sensors.getTempFByIndex(1) == 196.00){
    TempF1 = TempF1;
    Serial.print("POWER ERROR! SENDING OLD VALUE!");
  }
  else if (sensors.getTempFByIndex(1) == 196.60){
    TempF1 = TempF1;
    Serial.print("POWER ERROR! SENDING OLD VALUE!");
  }
  else if (sensors.getTempFByIndex(1) == 32.00){
    TempF1 = TempF1;
    Serial.print("CODE ERROR! SENDING OLD VALUE!");
  }
  else if (sensors.getTempFByIndex(1) == 185.00){
    TempF1 = TempF1;
    Serial.print("WIRING ERROR! SENDING OLD VALUE!");
  }
  else{
    TempF1 = sensors.getTempFByIndex(1);
  }
  
  //Asign TempF1 to payload, sending it as a string:
  dtostrf(TempF1,2,2,SendPayload);
  
  //Change the number after the "T" for eaach sensor. Follow the Numbering System.
  strcat(SendPayload, "-T00"); //Tags to help sort the data (Value, Sensor)
  
  //Send a heartbeat
  radio.stopListening();
  bool ok = radio.write(&SendPayload,strlen(SendPayload));
  Serial.print("");
  Serial.print("Sending: ");
  Serial.println(SendPayload);
  radio.startListening();
}

Any help would be much appreciated as I start school back on Tuesday again. If you need any more project background etc. or other relevant information to help please let me know!

Thanks!

The 85 simply means the sensor has not had time to do its job. It needs 750ms. If you just see this once, putting a delay(1000); in the setup will fix it.

Clearly, the loop cannot be a problem as you have big delays there already.

I don't think the cable length is unreasonable, so long as it is of good quality. You can buy DS18B20s with 5m cable, but you can have grief extending them with cheap stuff.

You might have good reason for that loop but you might also get a better idea of reading the sensors here