my project is a temperature-monitor for 5 rooms.
searching in web i found ds18b20 may fit for this generally..
2 days before i got the first pieces of the sensor as raw types in TO92.
as it is import to text with more than one sensors my first sketch
does Not use one-wire-selection but gets the values on 2 Pins !
That seemed easier for my start..
the main problem is heating of the sensors with different behaviour per sensor-piece
the other part of my issues is to optimize code..
//---------- DS18B20 Read-Examples from forum-arduino-posting
//- test_ds18b20_v2_i2c_2.ino
//- status : 31.12.2023
//- here we try to use 2 sensors
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS1 2
#define ONE_WIRE_BUS2 5
#define LCD_SHOW_TIME 1000
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire1(ONE_WIRE_BUS1);
OneWire oneWire2(ONE_WIRE_BUS2);
// Pass oneWire reference to Dallas Temperature library
DallasTemperature sensor1(&oneWire1);
DallasTemperature sensor2(&oneWire2);
// declare the lcd object for auto i2c address location
hd44780_I2Cexp lcd;
// LCD geometry
const uint8_t LCD_COLS = 16;
const uint8_t LCD_ROWS = 2;
uint8_t lcd_status = 0;
int sensorCount = 0;
int i = 0;
float temperatureC = 0.00;
void setup()
{
// Start serial communication for debugging
Serial.begin(9600);
lcd_status = lcd.begin(LCD_COLS, LCD_ROWS);
//Serial.print("Status : " + String(lcd_status));
if (lcd_status) // non zero status means it was unsuccessful
{
// begin() failed so blink error code using the onboard LED if possible
//hd44780::fatalError(status); // does not return
}
//- Print program release
lcd.clear();
lcd.print("test_ds18b20_v2_i2c_2.ino for Nano");
delay(LCD_SHOW_TIME);
// Initialize DS18B20 sensor
sensor1.begin();
sensorCount = sensor1.getDeviceCount();
//Serial.println("Count sensors :"+String(sensorCount));
lcd.clear();
lcd.print("Count sensor 1:" + String(sensorCount));
delay(LCD_SHOW_TIME);
sensorCount = sensor2.getDeviceCount();
lcd.print("Count sensor 2:" + String(sensorCount));
delay(LCD_SHOW_TIME);
lcd.clear();
lcd.print("Setup ready");
//Serial.println("Setup Ready !");
delay(LCD_SHOW_TIME);
};
void loop()
{
sensor1.begin();// Request temperature from the DS18B20 again
sensor1.requestTemperatures();
temperatureC = sensor1.getTempCByIndex(0);
lcd.clear();
lcd.print("Temp of 1 : " + String(temperatureC) + " °C");
delay(LCD_SHOW_TIME);
sensor2.begin();// Request temperature from the DS18B20 again
sensor2.requestTemperatures();
temperatureC = sensor2.getTempCByIndex(0);
lcd.clear();
lcd.print("Temp of 2 : " + String(temperatureC) + " °C");
delay(LCD_SHOW_TIME);
}
by the way have tried with NonBlockingDallas but that didnt work for me..(??)
what to do with the offset-temperature ?
as sensors behaviour is Not the same per sensor-piece
dont guess a generally offset potentiometer would help..
hi golem,
in the drawing i see pullup-resistor of 2,2k..other recommend 4,7k..
is that critical in any way ?
in my sketch for nano the used pins are 2 and 5.. other use different pins..but
nowhere is said whether that has any mention..
ok, i'll take a new try with using sensor-selection on One-Wire..would like that
because i could use the free pins for other things..
guess blocking seems Not to be the problem here as long avoiding too much delays..
//12-bit default resolution; external power supply
#include<OneWire.h>
OneWire ds(2);
byte addr1[8]; //to hold 64-bit ROM Codes of DS1
byte addr2[8]; //to ho;d 64-bit ROM-code DS2
byte data[9]; //buffer to hold data coming from DS18B20
float celsius;
void setup()
{
Serial.begin(9600);
ds.reset();
ds.search(addr1); //collect 64-bit ROM code from sensor (DS1)
ds.search(addr2);
}
void loop()
{
probe1();
probe2();
}
void probe1()
{
//----------------------------
ds.reset(); //bring 1-Wire into idle state
ds.select(addr1); //slect with DS-1 with address addr1
ds.write(0x44); //conversion command
delay(750); //data ready withinh DS18B20-1 or poll status word
//---------------------------
ds.reset();
ds.select(addr1); //selectimg the desired DS18B20-1
ds.write(0xBE); //Function command to read Scratchpad Memory (9Byte)
ds.read_bytes(data, 9); //data comes from DS and are saved into buffer data[8]
//---------------------------------
int16_t raw = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
celsius = (float)raw / 16.0; //12-bit resolution
Serial.print("Temp from Sensor-1: ");
Serial.println(celsius, 2);
}
void probe2()
{
ds.reset(); //bring 1-Wire into idle state
ds.select(addr2); //slect with DS-2 with address addr1
ds.write(0x44); //conversion command
delay(750); //data ready withinh DS18B20-2 or poll status word
//---------------------------
ds.reset();
ds.select(addr2); //selectimg the desired DS18B20
ds.write(0xBE); //Function command to read Scratchpad Memory (9Byte)
ds.read_bytes(data, 9); //data comes from DS and are saved into buffer data[8]
//---------------------------------
int16_t raw = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
celsius = (float)raw / 16.0; //12-bit resolution
Serial.print("Temp from Sensor-2: ");
Serial.println(celsius, 2);
}
Not 100% sure what your issue is, however I believe all the sensors are to be connected to one pin. Each sensor has a large (64 bit?) ID number. This number allows you to talk to each sensor.
The sensors need to be mounted onto something ( a heat sink would do ) to reduce self heating issues .
I’ve never seen that difference across sensors .
I would run the example Dallas code , separately , on each sensor , with each sensor next to one another ; so they should read the same . Let each stabilise for say 5mins .This will help identify where your issue resides .
Those sensors aren’t especially expensive, especially compared to the time you will waste on the now notorious fakes.
Find a reputable supplier to get you started with some genuine equipment - if you specify which country you’re in, there may be someone here that can recommend one.
I think I recall that the self heating is more pronounced when you read the sensors so you might consider reading them less frequently. How often is there a significant change?
I'm surprised that the rooms change temperature so quickly - what's in them? My one room residential project reads every ten minutes I think and that's ample.
If you want to read so frequently, test the real ones once you have them and see whether the heatsinks mentioned by @hammy would help.
ok,
the heatsinks have helped at 2 pieces, but temp of the one exemplar
remains at over 10 degress higher than room, though temp of the hot piece
does not go over 36 degrees then in opposite to nearly 40 degrees without heatsink.
i guess using sensors in tubes is the same effect like the heat sinks..