For a multi-house HVAC project, I need to use many (About 30) water temperature sensors…
My original choice of water temperature sensor was one with PWM output, needing one digital I/O pin per sensor.
In this thread: Calculating a median value we ( @Ric, @BulldogLowell, @ScruffR, @peekay123, @Moors7 and others ) worked on a a sketch to read the temperatures of 16 of these sensors with one Particle. That works fine!
However, for several reasons, I would like to use the DS18B20 sensors. The main reason is that I can monitor even more sensors with less pins (= Only one!).
Today I started to try out the DS18B20 one-wire sensor, and I managed to read out one without problems.
But when I look at all the discussions in this forum about using Multiple DS18B20 with Photon, I am confused by the various methods and libraries used by many of you.
Below, I post a basic “under construction” sketch, to display the temperatures of 8 of these sensors on the serial monitor. Of course, at this moment it measures only one sensor, but it does that 8 times in a row in the loop():
Can anyone show me a simple way to make it read 8 different sensors on the bus?
Once I will be able to do that, I can adapt it to my purposes.
/******************************************************************************************************
DS18B20_temperature_monitor.ino
Connections: Sensor Particle
------ --------
Red +5V (Vin)
Black Gnd
Yellow Any I/O (D2) => Attention: 4k7 pull-up resistor between yellow wire and +5V (May be reduced to 1k)
*******************************************************************************************************/
// Libraries for off-line use in the "Particle DEV" program:
#include "Particle-OneWire.h"
#include "DS18B20.h"
DS18B20 ds18b20 = DS18B20(D2); // Sets Pin D2 for Temp Sensor
float T1, T2, T3, T4, T5, T6, T7, T8;// Floating variables for calculations
void setup()
{
pinMode(D2, INPUT);
Serial.begin(9600);
}
void loop()
{
T1 = getTemp();
delay(500);
T2 = getTemp();
delay(500);
T3 = getTemp();
delay(500);
T4 = getTemp();
delay(500);
T5 = getTemp();
delay(500);
T6 = getTemp();
delay(500);
T7 = getTemp();
delay(500);
T8 = getTemp();
delay(500);
Serial.print(T1,1); Serial.print("-");
Serial.print(T2,1); Serial.print("-");
Serial.print(T3,1); Serial.print("-");
Serial.print(T4,1); Serial.print("-");
Serial.print(T5,1); Serial.print("-");
Serial.print(T6,1); Serial.print("-");
Serial.print(T7,1); Serial.print("-");
Serial.println(T8,1);
delay(500);
}
float getTemp()
{
float Reading;
if(!ds18b20.search())
{
ds18b20.resetsearch();
Reading = ds18b20.getTemperature();
if (Reading >0 && Reading <120) // Don't use "impossible" values!
{
return Reading;
}
}
}
BTW: Actually, I made this sketch for displaying the 8 temperatures on a mini OLED display, but I removed that part for simplification:
Thanks a lot for your time!