#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 12
// setup OneWire instance for communication with multiple DS18B20
OneWire oneWire(ONE_WIRE_BUS);
// DallasTemperature library for reading the temps
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
// locate sensors on the OneWire bus
Serial.print("Locating devices...");
deviceCount = sensors.getDeviceCount();
if (deviceCount == 0) {
Serial.println("Failed to find devices");
for(;;);
}
Serial.print("Found: ");
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
}
void loop() {
// put your main code here, to run repeatedly:
sensors.requestTemperatures();
for (int i = 0; i < deviceCount; i++)
{
Serial.print("Sensor ");
Serial.print(i+1);
Serial.print(" : ");
float tempC = sensors.getTempCByIndex(i);
Serial.print(tempC);
Serial.print((char)176);//shows degrees character
Serial.print("C");
}
Serial.println("");
delay(1000);
}