How to operate the DHT11 sensor with the 1602 lcd display on the Arduino

I have a DHT11 sensor and I can not get the temperature and humidity data to plot on the display.

Could someone help me where I can download the sensor library for the mega arduino 2560 and also the script?

thankful

Do you have the current IDE installed? The library manager offers several libraries for that sensor (BTW, it's a rather bad one, quite inaccurate and low resolution). All the libraries have example scripts which print the values to the serial interface. Changing them to print to the LCD is a rather easy task.

You seem to know that you need a library. What happens when you type "dht11 library" or "how to install arduino library" into Google?

97/500

pylon:
Do you have the current IDE installed? The library manager offers several libraries for that sensor (BTW, it's a rather bad one, quite inaccurate and low resolution). All the libraries have example scripts which print the values to the serial interface. Changing them to print to the LCD is a rather easy task.

pylon:
Do you have the current IDE installed? The library manager offers several libraries for that sensor (BTW, it's a rather bad one, quite inaccurate and low resolution). All the libraries have example scripts which print the values to the serial interface. Changing them to print to the LCD is a rather easy task.

97/5000
I downloaded a library that works, but it shows the data via serial, not display.

Good so far.

Have you checked the display works and can show some text like "hello"?

MorganS:
Good so far.

Have you checked the display works and can show some text like "hello"?

Exactly, by trial and error, until it works out.

Exactly, by trial and error, until it works out.

Now you can use the same library for the LCD, use the DHT sketch that prints to serial and replace the Serial.print() calls by a lcd.print() (or whatever object you use for the LCD). Try that and post the resulting code if you still have problems.

pylon:
Now you can use the same library for the LCD, use the DHT sketch that prints to serial and replace the Serial.print() calls by a lcd.print() (or whatever object you use for the LCD). Try that and post the resulting code if you still have problems.

What is happening in my case is that I have the 2560 mega arduino and most of the libraries I think are for the arduino uno. I have found a library that communicates with my arduino 2560 which is idDHT11, it worked, but on the serial monitor. Now I'm trying to make it work on the display, making some modifications, but it always appears compiling error for the board ArduinoGenuino Mega 2560

How are we to help you if you don't post the code and the error message(s)?

groundFungus:
How are we to help you if you don't post the code and the error message(s)?

My arduino is the Mega 2560. The code that is below I downloaded and is working, it reads the data of the sensor and appears the humidity and temperature, but only in the serial monitor.

/*

 Board          int.0  int.1  int.2  int.3  int.4  int.5
Uno, Ethernet  2  3
Mega2560  2  3  21  20  19  18
Leonardo  3  2  0  1
Due          (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
*/

#include <idDHT11.h>

int idDHT11pin = 2; //Digital pin for comunications
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)

//declaration
void dht11_wrapper(); // must be declared before the lib initialization

// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);

void setup()
{
 Serial.begin(9600);
 Serial.println("idDHT11 Example program");
 Serial.print("LIB version: ");
 Serial.println(IDDHT11LIB_VERSION);
 Serial.println("---------------");
}
// This wrapper is in charge of calling 
// mus be defined like this for the lib work
void dht11_wrapper() {
 DHT11.isrCallback();
}
void loop()
{
 Serial.print("\nRetrieving information from sensor: ");
 Serial.print("Read sensor: ");
 //delay(100);
 DHT11.acquire();
 while (DHT11.acquiring())
   ;
 int result = DHT11.getStatus();
 switch (result)
 {
 case IDDHTLIB_OK: 
   Serial.println("OK"); 
   break;
 case IDDHTLIB_ERROR_CHECKSUM: 
   Serial.println("Error\n\r\tChecksum error"); 
   break;
 case IDDHTLIB_ERROR_ISR_TIMEOUT: 
   Serial.println("Error\n\r\tISR Time out error"); 
   break;
 case IDDHTLIB_ERROR_RESPONSE_TIMEOUT: 
   Serial.println("Error\n\r\tResponse time out error"); 
   break;
 case IDDHTLIB_ERROR_DATA_TIMEOUT: 
   Serial.println("Error\n\r\tData time out error"); 
   break;
 case IDDHTLIB_ERROR_ACQUIRING: 
   Serial.println("Error\n\r\tAcquiring"); 
   break;
 case IDDHTLIB_ERROR_DELTA: 
   Serial.println("Error\n\r\tDelta time to small"); 
   break;
 case IDDHTLIB_ERROR_NOTSTARTED: 
   Serial.println("Error\n\r\tNot started"); 
   break;
 default: 
   Serial.println("Unknown error"); 
   break;
 }
 Serial.print("Humidity (%): ");
 Serial.println(DHT11.getHumidity(), 2);

 Serial.print("Temperature (oC): ");
 Serial.println(DHT11.getCelsius(), 2);

 Serial.print("Temperature (oF): ");
 Serial.println(DHT11.getFahrenheit(), 2);

 Serial.print("Temperature (K): ");
 Serial.println(DHT11.getKelvin(), 2);

 Serial.print("Dew Point (oC): ");
 Serial.println(DHT11.getDewPoint());

 Serial.print("Dew Point Slow (oC): ");
 Serial.println(DHT11.getDewPointSlow());

 delay(2000);
}



The code below was from a project that I found on the internet with the dht11 sensor along with a 1602 lcd display and an arduino uno. I made some adjustments to the code, the words temperature and humidity appear on the display, but this does not happen with data acquisition the sensor.


//Programa : Temperatura e umidade com o DHT11 e LCD 16x2
//Autor : FILIPEFLOP

#include <LiquidCrystal.h> //Carrega a biblioteca LCD
#include <idDHT11.h> //Carrega a biblioteca DHT

int idDHT11pin = 21; //Digital pin for comunications
int idDHT11intNumber = 2; //interrupt number (must be the one that use the previus defined pin (see table above)

//declaration
void dht11_wrapper(); // must be declared before the lib initialization


//Define a ligação ao pino de dados do sensor
#define DHTPIN 21

//Define o tipo de sensor DHT utilizado
#define DHTTYPE DHT11


//Define os pinos que serão ligados ao LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//Array simbolo grau
byte grau[8] ={ B00001100,  
               B00010010,
               B00010010,
               B00001100,
               B00000000,
               B00000000,
               B00000000,
               B00000000,};

void setup()
{
Serial.begin(9600); //Inicializa a serial
Serial.println("idDHT11 Example program");
Serial.print("LIB version: ");
Serial.println(IDDHT11LIB_VERSION);
Serial.println("---------------");
lcd.begin(16,2); //Inicializa LCD
lcd.clear(); //Limpa o LCD
//Cria o caractere customizado com o simbolo do grau
lcd.createChar(0, grau);
}


void loop()
{
Serial.print("\nRetrieving information from sensor: ");
 Serial.print("Read sensor: ");
 //delay(100);

 
 
float getCelsius();
 float getFahrenheit();
 float getKelvin();
lcd.setCursor(0,0);
lcd.print("Temp : ");
lcd.print(" ");
lcd.setCursor(7,0);
lcd.print(0,1);
lcd.setCursor(12,0);

//Mostra o simbolo do grau formado pelo array
lcd.write((byte)0);

//Mostra o simbolo do grau quadrado
//lcd.print((char)223);

lcd.setCursor(0,1);
lcd.print("Umid : ");
lcd.print(" ");
lcd.setCursor(7,1);
lcd.print(0,1);
lcd.setCursor(12,1);
lcd.print("%");


//Intervalo recomendado para leitura do sensor
delay(2000);
}


[code]

Please edit your post to add code tags. (See the how-to-use-this-forum guide.) The forum software eats some of your code if you don't.

You can upload and execute the following (tested) codes in your MEGA. I have used this Library.

#include "DHT.h"
#define DHTPIN 2        // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);
float humidity;
float temp;

void setup()
{
  Serial.begin(9600);
  dht.begin();
}

void loop()
{
  delay(2000);     //rsponse time of the DHT11 sensor
  //-------------------------------------------------
  humidity = dht.readHumidity();
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print(" %\t");
  //---------------------------------------------
  temp = dht.readTemperature();   //degree celsius
  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.print(" *C ");
  //--------------------------
  Serial.println();
}

//--------------------------------------------------------------------
To show the Humidity Value on Top Line and Temperature Value on Bottom Line of the LCD, you can place the following codes at the suitable places of the above program.

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //RS  EN  D4  D5  D6  D7
lcd.begin(16, 2);
lcd.setCursor(0,0);   //Display Position DP0 (0) of Top Line (0)
lcd.print("Humidity = ");
lcd.print(humidity, 2);
lcd.print("%");

lcd.setCursor(0, 1) //DP0 position of Bottom Line (1)
lcd.print("Temp = ");
lcd.print(temp, 2);
lcd.print(" ");
lcd.write(0xDF);
lcd.print("C");

I installed this library and this code, but it gave compilation error to the flat arduino

viniciusantonio:
I installed this library and this code, but it gave compilation error to the flat arduino

Pleased, post your compilation error message. What Arduino (UNO/MAGA/NANO/DUE) are you using?

Arduino: 1.8.5 (Windows 7), Placa:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from sketch\DHT_U.cpp:22:0:

sketch\DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory

 #include <Adafruit_Sensor.h>

                             ^

compilation terminated.

exit status 1
Erro compilando para a placa Arduino/Genuino Mega or Mega 2560

Este relatório teria mais informações com
"Mostrar a saida detalhada durante a compilação"
opção pode ser ativada em "Arquivo -> Preferências"

I'm using the Arduino Mega 2560

viniciusantonio:
error: Adafruit_Sensor.h: No such file or directory

This means the Adafruit_Sensor library is not installed properly on your computer. Did you download it? Did you put it in the right place?

If it came from Github, you need to remove "_master" from the folder name.

I'LL do what you recommeended.

I also did some downloads in the library manager of the arduino software.

[quote author=MorganS date=1532361241 link=msg=3815997]
This means the Adafruit_Sensor library is not installed properly on your computer. Did you download it? Did you put it in the right place? 

If it came from Github, you need to remove "_master" from the folder name.
[/quote]

I downloaded a bookstore that worked on my arduino mega 2560, but I can only read the sensor data on the serial monitor of the arduino software. Would you like to modify the code to throw that data on the display? I tried to, but until now I could not.

/*
Board int.0 int.1 int.2 int.3 int.4 int.5
Uno, Ethernet 2 3
Mega2560 2 3 21 20 19 18
Leonardo 3 2 0 1
Due (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
*/

#include <idDHT11.h>

int idDHT11pin = 21; //Digital pin for comunications
int idDHT11intNumber = 2; //interrupt number (must be the one that use the previus defined pin (see table above)

//declaration
void dht11_wrapper(); // must be declared before the lib initialization

// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);

void setup()
{
Serial.begin(9600);
Serial.println("idDHT11 Example program");
Serial.print("LIB version: ");
Serial.println(IDDHT11LIB_VERSION);
Serial.println("---------------");
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapper() {
DHT11.isrCallback();
}
void loop()
{
Serial.print("\nRetrieving information from sensor: ");
Serial.print("Read sensor: ");
//delay(100);
DHT11.acquire();
while (DHT11.acquiring())
;
int result = DHT11.getStatus();
switch (result)
{
case IDDHTLIB_OK:
Serial.println("OK");
break;
case IDDHTLIB_ERROR_CHECKSUM:
Serial.println("Error\n\r\tChecksum error");
break;
case IDDHTLIB_ERROR_ISR_TIMEOUT:
Serial.println("Error\n\r\tISR Time out error");
break;
case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
Serial.println("Error\n\r\tResponse time out error");
break;
case IDDHTLIB_ERROR_DATA_TIMEOUT:
Serial.println("Error\n\r\tData time out error");
break;
case IDDHTLIB_ERROR_ACQUIRING:
Serial.println("Error\n\r\tAcquiring");
break;
case IDDHTLIB_ERROR_DELTA:
Serial.println("Error\n\r\tDelta time to small");
break;
case IDDHTLIB_ERROR_NOTSTARTED:
Serial.println("Error\n\r\tNot started");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println(DHT11.getHumidity(), 2);

Serial.print("Temperature (oC): ");
Serial.println(DHT11.getCelsius(), 2);

Serial.print("Temperature (oF): ");
Serial.println(DHT11.getFahrenheit(), 2);

Serial.print("Temperature (K): ");
Serial.println(DHT11.getKelvin(), 2);

Serial.print("Dew Point (oC): ");
Serial.println(DHT11.getDewPoint());

Serial.print("Dew Point Slow (oC): ");
Serial.println(DHT11.getDewPointSlow());

delay(2000);
}