Completed my first project with the Arduino.
Display the temp and humidity from a DHT11 sensor on an LCD
Took me all day but finally got it done. Code is as follows
// display temp and humidity on LCD
#include <SimpleDHT.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd (4,5,6,7,8,9); //pins for RS, E, DB4, DB5, DB6, DB7
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int sensor = 10; // sensor is on pin 10
SimpleDHT11 dht11;
#define LED 11 // LED is on pin 11
void setup() {
// LCD setup
lcd.begin(16,2);
lcd.clear();
pinMode(LED,OUTPUT); // set led to output
}
void loop()
{
lcd.clear(); // clear LCD
// Sensor Check.
byte temperature = 0;
byte humidity = 0;
if (dht11.read(sensor, &temperature, &humidity, NULL)){
// if sensor shows no data let me know
lcd.setCursor(1,0);
lcd.print("**************");
lcd.setCursor(0,1);
lcd.print("**CHECK SENSOR**.");
delay(1000);
digitalWrite(LED,HIGH); // turn on LED if no data found
return;
}
// convert c to f
float c = 0;
float temp = 0;
c = temperature;
temp = (1.8 * c) + 32;
// Display data
digitalWrite(LED,LOW); // turn LED off
lcd.clear();
// Display Temp
lcd.setCursor(0,0);
lcd.print("TEMP ");
lcd.print(temp,1);
lcd.print(" F");
delay(5000);
// Display Humidity
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Humidity ");
lcd.print((int)humidity);
lcd.print("%");
delay(5000);
}
-
jlangbridge
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Comment-
jlangbridge
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Children