hi all,
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..
8 posts - 4 participants