#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// setup a onewire instance to communicate with any onewire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our onewire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start Serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Request to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celcius temperature: ");
// why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the Wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenhait temperature: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}