#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 12 // not used
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress Thermometer[12];
float tempC;
byte nsensors;
byte x;
char trenn = 9;
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
// zero pad the address if necessary
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
void setup() {
// start serial port
Serial.begin(9600);
Serial.println("Initalizing Dallas Temperature IC Control Library");
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
nsensors = sensors.getDeviceCount();
Serial.print(nsensors, DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
oneWire.reset_search();
for (x = 0; x < nsensors; x ++)
{
if (!oneWire.search(Thermometer[x])) Serial.println("Unable to find address for insideThermometer");
Serial.print("Device ");
Serial.print(x, DEC);
Serial.print(" Address: ");
printAddress(Thermometer[x]);
Serial.print(" Resolution: ");
Serial.print(sensors.getResolution(Thermometer[x]), DEC);
Serial.println();
}
}
void loop() {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
for (x = 0; x < nsensors; x ++)
{
tempC = sensors.getTempC(Thermometer[x]);
Serial.print(tempC);
Serial.print(trenn);
}
Serial.println();
delay(2000);
}