dht11 and ds18b20 differences

Hi all,

I have two sensors on arduino board, the dht11 (humidity and temp) and ds18b20 (temp only) but they read differents temperatures, it’s normal ? How to calibrate or compensate this problem.

This is a code:

//// INcludes
#include <dht11.h>
#include <DallasTemperature.h>


#define DHT11PIN 2

dht11 DHT11;
DallasTemperature tempSensor; // You may instantiate as many copies as you require.

void setup(void) {
// start serial port
tempSensor.begin(3); // Ds18b20 porta 3


void loop(void) {

//check status dht11

int chk = DHT11.read(DHT11PIN);
switch (chk)

case 0: Serial.println(“OK”); break;
case -1: Serial.println(“Checksum error”); break;
case -2: Serial.println(“Time out error on DHT11”); break;
default: Serial.println(“Unknown error”); break;

// Ask the library whether the device is valid
case 1:
Serial.println(“Problem ds18b20”);
tempSensor.reset(); // Attempts to redetect IC


// getTemperature returns a float.

Serial.print(" WaterSensor:");

Serial.println ();

Serial.print((float)DHT11.humidity, 2);

Serial.print(" Humidade ");

Serial.println ();

Serial.print((float)DHT11.temperature, 2);
Serial.print(" TempAmbiente: ");

Serial.println ();


Thank you

first please use the # button to post code (looks so much better)

2nd: Can you tell more about the difference you get, is it big or tiny? is it within the specs of the datasheet?

I know that for the DHT series it is advised to wait 2 seconds between readings... The DS18B20 is considered quite precise, 4 bits after the decimal point. Accuracy 0.5C IIIRC

Does the DHT11 not only return int's ? so the precission is 4 bit less than the DS18B20? Think the DS18 is the one to "believe"

Furthermore the DHT22 is more precise than the DHT11, it has some decimal places.

Tip, you might do an average over multiple readings something like

float DHTtemp = 0.0;


  // do what is necessary here
  DHTtemp = 0.9*DHTtemp + DHT11.temperature;

  // the DS18 code here