2016-02-14 12:13:03 +00:00
|
|
|
|
2016-02-26 21:16:12 +00:00
|
|
|
/*
|
|
|
|
LCD:
|
|
|
|
|
|
|
|
https://www.arduino.cc/en/Reference/LiquidCrystal
|
|
|
|
https://www.youtube.com/watch?v=dZZynJLmTn8
|
|
|
|
https://www.youtube.com/watch?v=R-CRIthB7ZY
|
|
|
|
http://howtomechatronics.com/tutorials/arduino/lcd-tutorial/
|
|
|
|
|
|
|
|
|
|
|
|
DHT (temp & hum)
|
|
|
|
|
|
|
|
https://github.com/adafruit/DHT-sensor-library/blob/master/examples/DHTtester/DHTtester.ino
|
2016-03-12 14:41:22 +00:00
|
|
|
|
|
|
|
Photoresistor
|
|
|
|
https://learn.adafruit.com/photocells/using-a-photocell
|
|
|
|
https://arduinodiy.wordpress.com/2013/11/03/measuring-light-with-an-arduino/
|
2016-02-26 21:16:12 +00:00
|
|
|
*/
|
2016-02-14 12:13:03 +00:00
|
|
|
|
|
|
|
#include <DHT.h>
|
|
|
|
#include <LiquidCrystal.h>
|
|
|
|
|
2016-02-26 21:16:12 +00:00
|
|
|
#define DHT_APin A0 // Pin Análogico al que he conectado el sensor de temperatura
|
2016-02-26 19:47:34 +00:00
|
|
|
#define DHT_Type DHT22 // mi sensor es el DHT11
|
2016-03-12 14:41:22 +00:00
|
|
|
#define PHOTORES_APin A2 // Pin Análogico al que he conectado el sensor de luz
|
2016-02-14 12:13:03 +00:00
|
|
|
|
|
|
|
// init
|
|
|
|
DHT dht(DHT_APin, DHT_Type);
|
2016-02-14 15:00:04 +00:00
|
|
|
LiquidCrystal lcd(9, 10, 4, 5, 6, 7); // syntax: LiquidCrystal(rs, enable, d4, d5, d6, d7)
|
2016-02-14 12:13:03 +00:00
|
|
|
|
2016-02-14 15:00:04 +00:00
|
|
|
int timer = 0;
|
2016-03-12 14:41:22 +00:00
|
|
|
int milis = 0;
|
|
|
|
int ticks = 0;
|
|
|
|
int tmp = 0;
|
|
|
|
int loops = 0;
|
|
|
|
int luzMin = 1024; // máximo de lectura para el sensor
|
|
|
|
int luzMax = 0;
|
|
|
|
long luzSum = 0; // value use to exceed INT
|
|
|
|
|
2016-02-14 12:13:03 +00:00
|
|
|
|
|
|
|
void setup() { // put your setup code here, to run once:
|
|
|
|
Serial.begin(9600);
|
|
|
|
dht.begin();
|
|
|
|
lcd.begin(16, 2);
|
2016-02-14 15:00:04 +00:00
|
|
|
|
2016-03-12 14:41:22 +00:00
|
|
|
lcd.print(" hue hue hue ");
|
2016-02-14 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
2016-03-12 14:41:22 +00:00
|
|
|
|
2016-02-14 12:13:03 +00:00
|
|
|
void loop() { // put your main code here, to run repeatedly:
|
2016-03-12 14:41:22 +00:00
|
|
|
timer = 59 - ((millis() / 1000) % 60);
|
|
|
|
if (timer == ticks) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ticks = timer;
|
|
|
|
loops++;
|
|
|
|
|
|
|
|
tmp = analogRead(PHOTORES_APin);
|
|
|
|
luzMin = min(luzMin, tmp);
|
|
|
|
luzMax = max(luzMax, tmp);
|
|
|
|
luzSum += tmp;
|
2016-02-14 15:00:04 +00:00
|
|
|
|
2016-03-12 14:41:22 +00:00
|
|
|
if (timer == 59) {
|
2016-02-14 15:00:04 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2016-02-14 12:13:03 +00:00
|
|
|
|
2016-02-14 15:00:04 +00:00
|
|
|
// Compute heat index in Celsius (isFahreheit = false)
|
|
|
|
float hic = dht.computeHeatIndex(t, h, false); // sensación térmica
|
2016-02-14 12:13:03 +00:00
|
|
|
|
2016-02-26 21:16:12 +00:00
|
|
|
|
2016-02-14 15:00:04 +00:00
|
|
|
// 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);
|
2016-03-12 14:41:22 +00:00
|
|
|
Serial.print(" la:");
|
|
|
|
Serial.print(luzSum/loops);
|
|
|
|
Serial.print(" ln:");
|
|
|
|
Serial.print(luzMin);
|
|
|
|
Serial.print(" lx:");
|
|
|
|
Serial.print(luzMax);
|
2016-02-14 15:00:04 +00:00
|
|
|
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(13, HIGH);
|
|
|
|
delay(100);
|
|
|
|
digitalWrite(13, LOW);
|
|
|
|
|
2016-03-12 14:41:22 +00:00
|
|
|
// reset counters
|
|
|
|
loops = 0;
|
|
|
|
luzMin = 1024;
|
|
|
|
luzMax = 0;
|
|
|
|
luzSum = 0;
|
2016-02-14 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
2016-03-12 14:41:22 +00:00
|
|
|
lcd.setCursor(10, 2);
|
|
|
|
lcd.print(tmp);
|
|
|
|
|
2016-02-14 15:00:04 +00:00
|
|
|
lcd.setCursor(14, 2);
|
|
|
|
if (timer < 10)
|
|
|
|
lcd.print(0);
|
|
|
|
lcd.print(timer);
|
2016-03-12 14:41:22 +00:00
|
|
|
|
|
|
|
delay(100);
|
2016-02-14 12:13:03 +00:00
|
|
|
}
|
2016-03-12 14:41:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Not used now
|
|
|
|
double Lux(int RawADC0) {
|
|
|
|
double Vout = RawADC0 * 0.0048828125;
|
|
|
|
//int lux=500/(10*((5-Vout)/Vout));//use this equation if the LDR is in the upper part of the divider
|
|
|
|
int lux = (2500 / Vout-500) / 10;
|
|
|
|
return lux;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* GRAFANA:
|
|
|
|
SELECT (2500 / (mean("avg") * 0.0048828125) - 500) / 10,
|
|
|
|
(2500 / (min("min") * 0.0048828125) - 500) / 10,
|
|
|
|
(2500 / (max("max") * 0.0048828125) - 500) / 10
|
|
|
|
FROM "luminosidad"
|
|
|
|
WHERE $timeFilter
|
|
|
|
GROUP BY time(2m)
|
|
|
|
*/
|