Created
November 24, 2013 21:36
-
-
Save SyNeto/7632714 to your computer and use it in GitHub Desktop.
Prueba libreria sensores DHTxx con display LCD 16*2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Se incluye la liberia del sensor DHTXX | |
#include <DHT.h> | |
// Se incluye la libreria del LCD | |
#include <LiquidCrystal.h> | |
// objeto LiquidCrystal, configuracion de pines | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
// Configuracion pin y tipo de sensor DHTXX | |
#define DHTPIN 13 // El pin en el que esta conectado el sensor | |
#define DHTTYPE DHT11 // El sensor conectado es un DHT11 | |
// objeto DHT | |
DHT dht(DHTPIN, DHTTYPE); | |
// Setup de la rutina | |
void setup(){ | |
// Inicia la comunicacin serial | |
Serial.begin(9600); | |
Serial.println("Prueba DHT11"); | |
// Setup LCD | |
lcd.begin(16,2); | |
lcd.setCursor(2,0); | |
lcd.print("Prueba DHT11"); | |
lcd.setCursor(0,1); | |
lcd.print("T:"); | |
lcd.setCursor(5,1); | |
lcd.print("C"); | |
lcd.setCursor(10,1); | |
lcd.print("H:"); | |
lcd.setCursor(15,1); | |
lcd.print("%"); | |
// Setup DHT11 | |
dht.begin(); | |
} | |
// Rutina | |
void loop(){ | |
// Se lee la temperatura del sensor | |
int t = dht.readTemperature(); | |
// Se lee la humedad del sensor | |
int h = dht.readHumidity(); | |
if(isnan(t) || isnan(h)){ | |
Serial.print("Error al leer el sensor"); | |
} else{ | |
// Se escribe la temperatura en el LCD | |
lcd.setCursor(3,1); | |
lcd.print(t); | |
// Se escribe la humedad en el LCD | |
lcd.setCursor(13,1); | |
lcd.print(h); | |
// Se envian las secturas por el serial | |
Serial.print("Temperatura: "); | |
Serial.print(t); | |
Serial.print("C\t"); | |
Serial.print("Humedad: "); | |
Serial.print(h); | |
Serial.print("%\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment