20 by 4 LCD with DHT-xx

I now have a working DHT-22 / DHT-11 working display with the 20 by 4 LCD display.
Maybe it might help someone.

// DHT-22 Sensor Temperature and humidity readings
// Dave,W. Final version
// New Name - today - Friday 05/24/2019

//Libraries
#include <DHT.h>;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//Constants
#define DHTPIN 7 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)

// Init DHT and LCD
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 hex or 39 decimal for a 20 chars and 4 line display

//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
float fahern; // Calculation from C to F

void setup()
{
hum = 1.00;
temp = 1.00;
fahern = 1.00;
dht.begin();
lcd.init(); // initialize the lcd
lcd.display(); // Turn on Backlight
lcd.backlight(); // Set brightness ?

}

void loop()
{
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
fahern=(1.80*temp+32);
fahern=(fahern+.005);

// Print temperature and humidity data to LCD
lcd.setCursor(0,0);
lcd.print(“Temperature “);
lcd.print(fahern,2);
lcd.print(” F”);
lcd.setCursor(0,1);
lcd.print(“Temperature “);
lcd.print(temp,2);
lcd.print(” C”);
lcd.setCursor(0,2);
lcd.print(“Humidity “);
lcd.print(hum,2);
lcd.print(” %”);

delay(5000); //Delay 5 sec.
}

Good on you!

Now go and read the instructions, then go back and modify your post (use the "More --> Modify" option to the bottom right of the post) to mark up the code (always of course, posting the complete code) as such so we can examine it conveniently and accurately. It is not appropriate to post a ".ino" file as an attachment unless it is simply too large - that means that you are expecting people to actually load it to their IDE to look at it and that is extra unnecessary labour. In fact, attachments do not always show properly on different operating systems.

If you do not mark it up as code, the code you post could well be garbled and is actually not so easy to read.

Note: Also mark up any data in the same way. This includes error output that you get from the IDE.

And - before posting any code, always use "Auto Format" in the Tools menu of the IDE to properly present the code.

In general, avoid unnecessary white space (blank lines). You should only use these to separate functional blocks of code. Yours is pretty good in this regard. :grinning:

Dave:

Are you sure this is the final version?

That reminds me of a map that I bought while searching out ghost towns in Colorado years ago. In bold letters it was labeled "Latest Edition". Several years later on a subsequent trip I bought a new map. As you might imagine it was also labeled "Latest Edition".

Getting back to your program - have you tried sticking your probe in the freezer and observing what happens on the display when the temperature drops below 10 degrees?

There's more to improve . . . .

Don