DHT11 with LCD on Arduino Uno

I hacked this DHT11 together today to show the outside temp/humidity. I normally test output to the Serial port but this time I did LCD and serial.  The clear case is a case from Maker Shed. Eventually all this will fit inside the box but until I’m satisfied I’m gonna let it hang…

Below is the code. I added the Dew Point in F.

[php]

// include the library code:
#include <LiquidCrystal.h>
#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 6
double DPC;

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 2, 3, 5, 4);

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);

Serial.begin(9600);
Serial.println(“DHT11 TEST PROGRAM “);
Serial.print(“LIBRARY VERSION: “);
Serial.println(DHT11LIB_VERSION);
}

void loop() {

int chk = DHT11.read(DHT11PIN);

Serial.print(“Read sensor: “);
switch (chk)
{
case 0: Serial.println(“OK”); break;
case -1: Serial.println(“Checksum error”); break;
case -2: Serial.println(“Time out error”); break;
default: Serial.println(“Unknown error”); break;
}

Serial.print(“Humidity (%): “);
Serial.println((float)DHT11.humidity, DEC);

Serial.print(“Temperature ( C): “);
Serial.println((float)DHT11.temperature, DEC);

Serial.print(“Temperature ( F): “);
Serial.println(DHT11.fahrenheit(), DEC);

lcd.setCursor(0, 0);
lcd.print(“H%:”);
lcd.print(DHT11.humidity, DEC);
lcd.print(” F:”);
printDouble((DHT11.fahrenheit()),100);

lcd.setCursor(0, 1);
DPC= DHT11.dewPoint();

Serial.print(“Dew Point ( F): “);
Serial.println((DPC * 1.8) + 32);
Serial.println(DPC);
lcd.print(“DP(F): “);
//lcd.print((1.8 * (DHT11.dewPoint(), DEC) + 32));
lcd.print((DPC * 1.8) + 32);

Serial.print(“Dew Point ( C): “);
Serial.println(DHT11.dewPoint(), DEC);

Serial.print(“Dew PointFast ( C): “);
Serial.println(DHT11.dewPointFast(), DEC);

delay(10000);

}

void printDouble( double val, unsigned int precision){
// prints val with number of decimal places determine by precision
// NOTE: precision is 1 followed by the number of zeros for the desired number of decimial places
// example: printDouble( 3.1415, 100); // prints 3.14 (two decimal places)

Serial.print (int(val)); //prints the int part
Serial.print(“.”); // print the decimal point
unsigned int frac;
if(val >= 0)
frac = (val – int(val)) * precision;
else
frac = (int(val)- val ) * precision;

Serial.println(frac,DEC) ;
lcd.print(val);
lcd.print(frac,DEC) ;
}[/php]

Author: Helicopter Jeff

I'm a vinyl decal cutting and designing, Astrophotography and general photography capturing, RC helicopter/quad copter pilot, Arduino and Raspberry Pi hardware/software developer, network, scripting and troubleshooting ninja living in the metro NY area. I am passionate about my hobbies so much I do them for a living. There's nothing better than getting paid to do what you love.

1 thought on “DHT11 with LCD on Arduino Uno”

  1. I’m using PaleMoon (i.e. Firefox) and your sketch includes some HTML lines etc.

    Otherwise looks good, now if I can just get it working….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s