I'm trying to measure the temperature using a DS18B20 sensor. I'm using the DallasTemperature and OneWire Libraries. The sensor is connect in Pin 10 with a 4k7 resistor between VDD and DQ (actually I'm using 4x 1k and 2x 330 ohms) as so:
Here's the code I'm using:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 10
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float celsius;
void setup(void) {
Serial.begin(9600);
sensors.setResolution(12);
sensors.begin();
}
void loop(void) {
sensors.requestTemperatures();
celsius = sensors.getTempCByIndex(0);
Serial.println(celsius);
}
The sensor is outputing values close to the actual temperature (measure with a mercury thermometer), but a bit off.
Example:
Sensor Temperaute: 34.44°C
Thermometer Temperature: ~32°C
Why is that? And how can I fix it?