/* DS18B20 Sensor Arduino Uno */
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempadr = { 0x28, 0xFF, 0x5E, 0x18, 0x04, 0x15, 0x03, 0x34 };
void setup()
{
Serial.begin(9600);
sensors.begin();
sensors.setResolution(tempadr, 10);
}
void printTemp(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop()
{
delay(2500);
Serial.print("Getting Temperatures...\n\r");
sensors.requestTemperatures();
Serial.print("Temperature: ");
printTemp(tempadr);
Serial.print("\n\r");
}