From a28b1ec4004283141a9975880c637f5338650b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Sun, 14 Feb 2016 13:13:03 +0100 Subject: [PATCH] =?UTF-8?q?funci=C3=B3n=20b=C3=A1sica=20de=20LCD=20con=20i?= =?UTF-8?q?nfo=20del=20sensor=20de=20temperatura?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit primera prueba del LCD --- .../sketch_feb13b_DHT11_temp_hum.ino | 52 ++++++------- sketch_lcd/sketch_lcd.ino | 75 +++++++++++++++++++ 2 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 sketch_lcd/sketch_lcd.ino diff --git a/sketch_feb13b_DHT11_temp_hum/sketch_feb13b_DHT11_temp_hum.ino b/sketch_feb13b_DHT11_temp_hum/sketch_feb13b_DHT11_temp_hum.ino index 1f5c7fe..8980a4e 100644 --- a/sketch_feb13b_DHT11_temp_hum/sketch_feb13b_DHT11_temp_hum.ino +++ b/sketch_feb13b_DHT11_temp_hum/sketch_feb13b_DHT11_temp_hum.ino @@ -8,37 +8,37 @@ DHT dht(DHT_APin, DHT_Type); int ledPin = 13; void setup() { // put your setup code here, to run once: - Serial.begin(9600); - dht.begin(); - pinMode(ledPin, OUTPUT); + Serial.begin(9600); + dht.begin(); + pinMode(ledPin, OUTPUT); } void loop() { // put your main code here, to run repeatedly: - delay(60000); // 1 minuto + delay(60000); // 1 minuto - // Reading temperature or humidity takes about 250 milliseconds! - // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) - float h = dht.readHumidity(); - float t = dht.readTemperature(); // lectura en Celsius, readTemperature(true) para Fahrenheit + // Reading temperature or humidity takes about 250 milliseconds! + // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) + float h = dht.readHumidity(); + float t = dht.readTemperature(); // lectura en Celsius, readTemperature(true) para Fahrenheit - if (isnan(h) || isnan(t)) { - Serial.println("E"); // E = error, para el script en python que lee - return; - } + if (isnan(h) || isnan(t)) { + Serial.println("E"); // E = error, para el script en python que lee + return; + } - // Compute heat index in Celsius (isFahreheit = false) - float hic = dht.computeHeatIndex(t, h, false); // sensación térmica + // Compute heat index in Celsius (isFahreheit = false) + float hic = dht.computeHeatIndex(t, h, false); // sensación térmica - // D = DHT, para el script en python que leerá esto - Serial.print("D h:"); - Serial.print(h); - Serial.print(" t:"); - Serial.print(t); - Serial.print(" i:"); - Serial.print(hic); - Serial.println(""); - - digitalWrite(ledPin, HIGH); - delay(100); - digitalWrite(ledPin, LOW); + // D = DHT, para el script en python que leerá esto + Serial.print("D h:"); + Serial.print(h); + Serial.print(" t:"); + Serial.print(t); + Serial.print(" i:"); + Serial.print(hic); + Serial.println(""); + + digitalWrite(ledPin, HIGH); + delay(100); + digitalWrite(ledPin, LOW); } diff --git a/sketch_lcd/sketch_lcd.ino b/sketch_lcd/sketch_lcd.ino new file mode 100644 index 0000000..842a936 --- /dev/null +++ b/sketch_lcd/sketch_lcd.ino @@ -0,0 +1,75 @@ + +// https://www.arduino.cc/en/Reference/LiquidCrystal +// https://www.youtube.com/watch?v=dZZynJLmTn8 +// http://howtomechatronics.com/tutorials/arduino/lcd-tutorial/ + +#include +#include + +#define DHT_APin A0 // Pin Análogico al que he conectado el sensor +#define DHT_Type DHT11 // mi sensor es el DHT11 + +// init +DHT dht(DHT_APin, DHT_Type); +LiquidCrystal lcd(9, 10, 4, 5, 6, 7); // syntax: LiquidCrystal(rs, enable, d4, d5, d6, d7) + +// defs +int ledPin = 13; + +void setup() { // put your setup code here, to run once: + Serial.begin(9600); + dht.begin(); + lcd.begin(16, 2); + pinMode(ledPin, OUTPUT); + + lcd.print(" hue hue"); + lcd.setCursor(0, 2); + lcd.print(" boot"); + delay(500); + lcd.print("."); + delay(500); + lcd.print("."); + delay(500); + lcd.print("."); + delay(1000); + +} + +void loop() { // put your main code here, to run repeatedly: + + // Reading temperature or humidity takes about 250 milliseconds! + // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) + float h = dht.readHumidity(); + float t = dht.readTemperature(); // lectura en Celsius, readTemperature(true) para Fahrenheit + + if (isnan(h) || isnan(t)) { + Serial.println("E"); // E = error, para el script en python que lee + return; + } + + // Compute heat index in Celsius (isFahreheit = false) + float hic = dht.computeHeatIndex(t, h, false); // sensación térmica + + // D = DHT, para el script en python que leerá esto + Serial.print("D h:"); + Serial.print(h); + Serial.print(" t:"); + Serial.print(t); + Serial.print(" i:"); + Serial.print(hic); + Serial.println(""); + + lcd.clear(); + lcd.print(t); + lcd.print("C "); + lcd.print(h); + lcd.print("%"); + lcd.setCursor(0, 2); + lcd.print(hic); + lcd.print("C"); + + digitalWrite(ledPin, HIGH); + delay(100); + digitalWrite(ledPin, LOW); + delay(60000); // 1 minuto +}