Hello, looking for an easy solution ...
I'm bidding a steering to my stove where I want to use ds18b20 as a temperature sensor (It's the water temperature I feel so it does not get over 100C degrees hot)
I want to use 2 ~ 3 sensors ...
The problem:
If I use the 2 ~ 3 sensors on the same port, I need to re-register them if one breaks and a new one needs to be installed.
So I thought what if I use multiple input pins ...
Could it be done ...
and is there anyone who has a suggestion
Question not understood!
A DS18B20 has a unique address (serial number / name), so in order to know which one is getting data on the bus, you have to register any single sensor, which means changing a sensor, the old address does not work anymore need to register a new address that fits the new sensor...
I have worked with this code but the address ar a bit random ...
I'm looking for a solution where this code is actually used, or the idea itself.
where I can connect a DS18B20 sensor and then automatically register.
but on 3 different ports, with 3 different sensors
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
Based on the Dallas Temperature Library example
*********/
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}
Hi, this is my newest offer ...
It works all the way ..
But it's probably the wrong way to do it
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
Based on the Dallas Temperature Library example
*********/
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 2
//#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices
//OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
//DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
//sensors.begin();
}
void loop(void) {
tempsens_1();
delay(10);
tempsens_2();
delay(10);
}
void tempsens_1()
{
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//DallasTemperature sensors(&oneWire);
sensors.begin();
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature 1: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature 1: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}
void tempsens_2()
{
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//DallasTemperature sensors(&oneWire);
sensors.begin();
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature 2: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature 2: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}
or an array of them. That would stop the multiple calls of begin().
I suspect the library accomplishes communication via bit banging and timers are used and will overlap by the multiple instances.
It would be wiser to program the system to auto detect one sensor and assign it to the first location. Then attach a second and attach to the next location, and so on. Storing each of the addresses in the EEEPROM. If no sensors are attached, then clear. If the first or middle sensor dies, disconnect all to reset, then connect a new sensor and re-execute the setup procedure. In the way you are now using the standard library in a standard way.
Yes i hear you ..
Only problem is ...
I travel a lot and the person who needs to take care of my house when I'm away should have it as easy as possible so if a sensor is defective, it's easy and quick to change ...
so !!!!!
I have tried to take sensors.begin (); out and only call it once it does not work ...
A system that doesn't work due to poor programming isn't going to help your caretaker either. I don't know how reliable this is going to be, therefore based on past experience I'm voting 'not so reliable'. Hope you prove this wrong.
Are you calling it once or once per instance? You should only be calling it once per instance. Currently you call begin() for each instance every time you call the function. Move the definitions to global and the begin() calls to setup().
kimjessen:
Question not understood!
A DS18B20 has a unique address (serial number / name), so in order to know which one is getting data on the bus, you have to register any single sensor, which means changing a sensor, the old address does not work anymore need to register a new address that fits the new sensor...
If you connect every sensor to its own pin you can use the SKIP ROM command before issuing any other command so the (only) sensor will respond regardless of its address. RTFM (Read the friendly manual)
olf2012:
If you connect every sensor to its own pin you can use the SKIP ROM command before issuing any other command so the (only) sensor will respond regardless of its address. RTFM (Read the friendly manual)
Which do you accomplish this using the commands in the OneWire library?
If each sensor is connected to its own pin, then each pin has its own instance (right word?) of OneWire and DallasTemperature. Then it is a simple matter to call getTempFByIndex(0) and the only sensor on that pin in that instance will be index 0.
The second half of the OP's plan is good. The problem lies in the fact that I doubt the OneWire library was designed to have multiple instances active.
OneWire works great with several copies of it looking at several pins. I've got some fairly complex projects where there's many OneWire pins. One of them the battery temperature is the only sensor connected to that pin. Each time it switches on, it finds whatever sensor is there and uses that to report battery temperature. On another pin, I have a lot of DS18B20's and I have a little menu system in the Arduino that allows me to configure which sensor is which by plugging in my PC with the Serial Monitor and selecting the addresses.
But being able to hot-swap sensors without turning the system off? I think the only problem you will ever encounter is if you used setResolution(). The new sensor just plugged in hasn't seen that command so it will still be reporting in the default resolution.
The DS18B20 is pretty damn reliable. I've never seen one fail and I've pushed them past their datasheet limits repeatedly. The most likely failure mode is a broken wire. Make sure the cat can't chew on the wires.
The premise that these sensors might need replacing on some sort of regular basis is wrong - they will last for years and years - those in my house have run for 5 yrs with no failures .
So.... you might be going to unnecessary complex software lengths just to be able to replace a sensor - I’d thought it more likely the Arduino failed !!
The Maxim site gives a MTBF which means you won’t have to worry in your lifetime
kimjessen:
Question not understood!
A DS18B20 has a unique address (serial number / name), so in order to know which one is getting data on the bus, you have to register any single sensor, which means changing a sensor, the old address does not work anymore need to register a new address that fits the new sensor...
Why would you need to change a sensor? They are very reliable in my experience, and i've used dozens
installed in sensor networks over years.
kimjessen:
Hello, looking for an easy solution ...
I'm bidding a steering to my stove where I want to use ds18b20 as a temperature sensor (It's the water temperature I feel so it does not get over 100C degrees hot)
I want to use 2 ~ 3 sensors ...
The problem:
If I use the 2 ~ 3 sensors on the same port, I need to re-register them if one breaks and a new one needs to be installed.
So I thought what if I use multiple input pins ...
Could it be done ...
and is there anyone who has a suggestion
Regards Kim Jessen
Yes. I have the same issue in that this is going to be duplicated (hopefully) many times, and so simplest is to use two signal pins with two 4.7 K resistors. I need two temperatures to be checked.
This is in a new situation every time. Program the processor (Mega) and then use any ds18b20 on either pin. And if one gets damaged then no problem just plugging in a new random one. No addressing needed. And the coding is pretty simple.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
//Temp Sensors pin
const int waterTempSensorPin = A4;
const int heaterTempSensorPin = A5;
//Setup OneWire
OneWire waterTempOneWire(waterTempSensorPin);
OneWire heaterTempOneWire(heaterTempSensorPin);
//Setup temp sensors
DallasTemperature waterTempSensor(&waterTempOneWire);
DallasTemperature heaterTempSensor(&heaterTempOneWire);
void setup() {
waterTempSensor.begin();
heaterTempSensor.begin();
//add all your setup code also
}
void loop() {
Serial.print("Water Temperature: ");
Serial.print(getWaterTemperature());
Serial.print(char(176));
Serial.println("C");
Serial.print("Heater Temperature: ");
Serial.print(getHeaterTemperature());
Serial.print(char(176));
Serial.println("C");
//There is a bunch of other code in my program, so this would be ridiculous to just loop the temp over //and over.
}
float getWaterTemperature(){
waterTempSensor.requestTemperatures();
return waterTempSensor.getTempCByIndex(0);
}
float getHeaterTemperature(){
heaterTempSensor.requestTemperatures();
return heaterTempSensor.getTempCByIndex(0);
}
You can address the temperature directly also or use the "get####Tempurature" functions.
Also, there is a set of functions available to find the addresses and then use them directly off of one pin, but the code is pretty big and it takes up processor time.
Thanks for your post! It looks really simple and useful! Just one question: does <Wire.h> used by you app for other reason? I did not found where it used in code that you publish as example.