Code gets:
- Temperature and Humidity from a DHT11 sensor
Prints the data to the Serial Monitor
Data is printed onto a LCD display
Please let me know if you experience any problems with this
code. Be sure to check back for more Arduino code.
Schematic:
Code:
/*
Oliver Holden
Created 28/10/2014
Components:
* Arduino UNO
* DHT11
* 4.7K resistor
* LCD
- Gets Temperature and Humidity from a DHT11 sensor
Prints the data to the Serial Monitor
Data is printed onto a LCD display
Schematic for this project is on
http://breadboarder.blogspot.co.uk/
*/
#include <LiquidCrystal.h> // Including Libaries needed
#include <dht.h>
dht DHT; // Need this
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel
int dht_dpin = A0; // DHT11 Data pin attached to A0
void setup(){
Serial.begin(9600); // Opening serial connection at 9600bps
lcd.begin(16, 2); // Starting LCD libary and setting character size of LCD (X, Y)
lcd.setCursor(0,0); // Setting starting position of text
}
void loop(){
DHT.read11(dht_dpin); // Reading Data from DHT11
delay(2000); // 2s delay beween reading DHT11
{
// Printing data to LCD
lcd.setCursor(0,0); // move cursor to first line 0 and 9 spaces over
lcd.print("Temp = ");
lcd.print(DHT.temperature);
lcd.print(" C");
lcd.setCursor(0,1); // move cursor to second line 1 and 9 spaces over
lcd.print("Hum = ");
lcd.print(DHT.humidity);
lcd.print(" % ");
}
// Printing data to Serial Monitor
lcd.print("Temp = ");
lcd.print(DHT.temperature);
lcd.print(" C");
lcd.print(",");
lcd.print("Hum = ");
lcd.print(DHT.humidity);
lcd.print(" % ");
}