// C++ code
/*
ENLACE CÓDIGO
https://www.luisllamas.es/arduino-dht11-dht22/
*/
///////LIBRERIAS///////
#include <Adafruit_NeoPixel.h>
#include <DHT.h>
///////FIN LIBRERIAS///////
//------------------------------//
///////VARIABLES///////
int dist = 0;
int aviso = 0;
int aviso_arriba=0;
///////FIN VARIABLES///////
//------------------------------//
/////////CÓDIGO 1/////////
//#define DHTTYPE DHT11 //
//#define DHTPIN 2
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Initialize DHT sensor for normal 16mhz Arduino:
//DHT dht = DHT(DHTPIN, DHTTYPE);
/////////FIN CÓDIGO 1/////////
//------------------------------//
/////////CÓDIGO 2/////////
#define DHTTYPE DHT22
const int DHTPin = 2; // what digital pin we're connected to
DHT dht(DHTPin, DHTTYPE);
/////////FIN CÓDIGO 2/////////
//------------------------------//
Adafruit_NeoPixel pixels_abajo = Adafruit_NeoPixel(8,3,NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel pixels_arriba = Adafruit_NeoPixel(8,2,NEO_RGB + NEO_KHZ800);
void setup()
{
Serial.begin(9600);
pinMode(1,INPUT);
pinMode(11,INPUT); //pin led de la derecha
pinMode(12,OUTPUT); //pin led del medio
// Setup sensor:
dht.begin();
}
/* ////CÓDIGO 1////
void loop()
{
// Wait a few seconds between measurements:
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read the humidity in %:
float h = dht.readHumidity();
// Read the temperature as Celsius:
float t = dht.readTemperature();
// Read the temperature as Fahrenheit:
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again):
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (default):
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius:
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" \xC2\xB0");
Serial.print("C | ");
Serial.print(f);
Serial.print(" \xC2\xB0");
Serial.print("F ");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" \xC2\xB0");
Serial.print("C | ");
Serial.print(hif);
Serial.print(" \xC2\xB0");
Serial.println("F");
}
*/ ////FIN CÓDIGO 1////
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
}