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 suggestionRegards 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.