I have 6 DS18B20 temperature sensors on one circuit. Five (5) of the sensors work just fine, but the 6th spends half it’s time reading 185°f and the other half reading the outside temperature. I have I believe the latest One-Wire and Dallas Temp libraries. I have a delay of 10 seconds (10000) after the sensors.requestTemperatures and before the first sensors.getTempF(S1). I don’t think it’s the code but this is my first project, I’ve been working on it for over a year on and off.
I think it’s the length of the Cat 5 wire to the outside sensor, which is about 60 feet. I’ve tried using a small resistor, 1k and 2k, it did not seem to help. I’ve checked the volts from the Arduino Uno, it was 4.74 volts. I am using the Nextion 3.5 display powered from the Arduino. I tried powering the display separately, again it did not make a difference.
On the Brick-Temperature-DS18B20 site, it showed one wire for 5v, which is what I did. I’m wondering if I should have used a twisted pair of wires and used both wires to supply the 5 volts ?
Any suggests as to what is should do next?
Thank for your help.
here is my code
// started on this 9 jan 2018
#include "Nextion.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8
#define SENSOR_RESOLUTION 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int countloop = 0;
int numberOfDevices;
float ait = 0; // actual inside air temperature
float aot = 0; // actual outside air temperature
float pst = 0; // boiler premix supply water temperature
float prt = 0; // boiler premix return water temperature
float fst = 0; // floor supply water temperature
float frt = 0; // floor return water temperature
DeviceAddress S1 = { 0x28, 0xFF, 0xEA, 0xD9, 0x22, 0x17, 0x04, 0x85 };// sensor # 1
DeviceAddress S2 = { 0x28, 0xFF, 0xBE, 0x24, 0x23, 0x17, 0x04, 0x48 };// sensor # 2
DeviceAddress S3 = { 0x28, 0xFF, 0x4C, 0x12, 0x23, 0x17, 0x04, 0x2C };// sensor # 3
DeviceAddress S4 = { 0x28, 0xFF, 0xD9, 0x14, 0x23, 0x17, 0x04, 0x40 };// sensor # 4
DeviceAddress S5 = { 0x28, 0xFF, 0x97, 0xD9, 0x22, 0x17, 0x04, 0x04 };// sensor # 5
DeviceAddress S7 = { 0x28, 0xFF, 0xEB, 0x22, 0x23, 0x17, 0x04, 0x06 };// sensor # 7
//DeviceAddress S8 = { 0x28, 0xFF, 0x43, 0x1B, 0x23, 0x17, 0x04, 0xD0 };// sensor # 8
//DeviceAddress S10 = {0x28, 0xFF, 0xB7, 0x15, 0x23, 0x17, 0x04, 0x7C };// sensor # 10
// Declare your Nextion objects - Example (page id = 0, component id = 1, component name = "b0")
NexText tinsidetemp = NexText(0, 2, "tinsidetemp"); //sensors.getTempF(S1)
NexText toutsidetemp = NexText(0, 4, "toutsidetemp"); //sensors.getTempF(S2)
//NexNumber nsettemp = NexNumber(1, 3, "nsettemp");
//NexText twindspeed = NexText(2, 9, "twindspeed");
//NexText twinddirection = NexText(2, 10, "twinddirection")
//NexText tfeelslike = NexText(2, 11, "tfeelslike");
//NexText tpressure = NexText(3, 7, "tpressure");
//NexText thumidity = NexText(3, 8, "thumidity");
//NexText trainfall = NexText(3, 9, "trainfall");
NexText tpremix = NexText(4, 12, "tpremix"); //sensors.getTempF(S3)
NexText tsupply = NexText(4, 14, "tsupply"); //sensors.getTempF(S4)
NexText treturn = NexText(4, 15, "treturn"); //sensors.getTempF(S5)
NexText tpostmix = NexText(4, 13, "tpostmix"); //sensors.getTempF(S7)
NexNumber ncounter = NexNumber(0, 9, "ncounter");
NexNumber nsensors = NexNumber(0, 11, "nsensors");
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
sensors.begin();
numberOfDevices = sensors.getDeviceCount();
}
void loop() {
countloop++;
ncounter.setValue(countloop);
nsensors.setValue(numberOfDevices);
sensors.requestTemperatures();
sensors.setWaitForConversion(true);
delay(10000);
// the different sensors in F°
ait = sensors.getTempF(S1); // actual inside air temperature
aot = sensors.getTempF(S2); // actual outside air temperature
pst = sensors.getTempF(S3); // boiler premix supply water temperature
fst = sensors.getTempF(S4); // floor supply water temperature
frt = sensors.getTempF(S5); // floor return water temperature
prt = sensors.getTempF(S7); // boiler premix return water temperature
char abc[10];
dtostrf(ait,6,1,abc);
tinsidetemp.setText(abc);
char def[10];
dtostrf(aot,6,1,def);
toutsidetemp.setText(def);
char ghi[10];
dtostrf(pst,6,1,ghi);
tpremix.setText(ghi);
char jkl[10];
dtostrf(fst,6,1,jkl);
tsupply.setText(jkl);
char mno[10];
dtostrf(frt,6,1,mno);
treturn.setText(mno);
char pqr[10];
dtostrf(prt,6,1,pqr);
tpostmix.setText(pqr);
}