If you want to read a lot of DS18B20s and display the reported temperatures of each sensor, take a look at my blog, Multi temperature-humidity sensing with an Arduino Nano – TFT display: sketch updated. That one reads seven DS18B20 sensors and displays on a 320x480 TFT display
(Multi temperature-humidity sensing with an Arduino Nano – TFT display: sketch updated – thesolaruniverse)
There is a sketch attached at the end of that blog..
Here is a simple multiple DS18B20 sketch (3 sensors) storing the temperature data in variables Temp1, Temp2 and Temp3.
// read_DS18B20_into_variable_OK
// this sketch uses Dallas D18B20 one wire temperature sensors
// reads temperature of each sensor and stores the temperature value in a variable
// Floris Wouterlood 12 January 2016
// Thanks to everybody of the Arduino community
// DS18B20 Pinout (left to right, pins down, flat side toward you)
// - Left = Ground
// - Center = Signal (Pin 2): (with 3.3K to 4.7K resistor to +5 or 3.3 )
// - Right = +5 or +3.3 V
#include <OneWire.h>
#include <DallasTemperature.h>
// ================================= Bus on pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// ================================= Setup a oneWire bus
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// ================================= Probe addresses
DeviceAddress probe_01 = { 0x28, 0xFF, 0x1C, 0x76, 0xA3, 0x15, 0x04, 0xD4 };
DeviceAddress probe_02 = { 0x28, 0xFF, 0x96, 0x74, 0xA3, 0x15, 0x04, 0xA5 };
DeviceAddress probe_03 = { 0x28, 0xFF, 0x7B, 0x74, 0xA3, 0x15, 0x04, 0x93 };
// ================================= number of temperature devices found
int numberOfDevices;
// ================================= variables used for control logic
float Temp1, Temp2, Temp3; // storage variables temperature sensors
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
Serial.println ("starting one wire sensors");
Serial.print("initializing Temperature Control Library, version ");
Serial.println(DALLASTEMPLIBVERSION);
sensors.begin();
// locate devices on the one wire bus
Serial.println("");
Serial.print("....... found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices ..........");
// set the resolution to 10 bit (good enough?)
sensors.setResolution(probe_01, 10);
sensors.setResolution(probe_02, 10);
sensors.setResolution(probe_03, 10);
delay (2000);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
}
}
void loop(void)
{
sensors.requestTemperatures();
// ================================= load variables with sensor values
Temp1 = sensors.getTempC(probe_01);
Temp2 = sensors.getTempC(probe_02);
Temp3 = sensors.getTempC(probe_03);
// ================================= serial monitor part ==========================
Serial.println("===================================");
Serial.print("Probe_01 temperature: ");
Serial.print(Temp1,1);
Serial.println(" *C");
Serial.print("Probe_02 temperature: ");
Serial.print(Temp2,1);
Serial.println(" *C ");
Serial.print("Probe_03 temperature: ");
Serial.print(Temp3,1);
Serial.println(" *C");
Serial.println(" ");
delay (4000);
}