Also, my IO platform is receiving NAN reading form a sensor that is connected as well, a DTH22. Why is that?
Code: Select all
#include "config.h"
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define HUMTEMP 2
#define SENSLUZ 5
#define SENSLLUV 12
#define SENSHUMSUELO 14
#define VALV0 0
// button state
bool current = false;
bool current1 = false;
bool current2 = false;
// create DHT22 instance
DHT_Unified dht(HUMTEMP, DHT22);
// set up the feeds
AdafruitIO_Feed *temperature = io.feed("temperature");
AdafruitIO_Feed *humidity = io.feed("humidity");
AdafruitIO_Feed *light= io.feed("light");
AdafruitIO_Feed *soil = io.feed("soil");
AdafruitIO_Feed *rain = io.feed("rain");
AdafruitIO_Feed *valve1 = io.feed("valve1");
void setup() {
pinMode(SENSLUZ, INPUT); //Fotoresistencia
pinMode(SENSLLUV, INPUT); //Sensor de lluvia
pinMode(SENSHUMSUELO, INPUT); //Sensor humedad suelo
pinMode(HUMTEMP, INPUT); //Sensor humedad-temperatura
pinMode(VALV1, OUTPUT); //Salida valvula 1
pinMode(VALV2, OUTPUT); //Salida valvula 2
pinMode(VALV3, OUTPUT); //Salida valvula 3
pinMode(VALV0, OUTPUT); //Salida valvula 4
Serial.begin(115200);
while(! Serial);
// initialize dht22
dht.begin();
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
valve1->onMessage(handleMessage);
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
valve1->get();
}
void handleMessage(AdafruitIO_Data *data){
Serial.print("Received <- ");
if(data->toPinLevel() == HIGH)
Serial.println("HIGH");
else
Serial.println("LOW");
digitalWrite(VALV1, data->toPinLevel());
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
sensors_event_t event;
dht.temperature().getEvent(&event);
float celsius = event.temperature;
Serial.println();
Serial.print("Temperatura: ");
Serial.print(celsius);
Serial.println("°C");
temperature->save(celsius);
dht.humidity().getEvent(&event);
Serial.print("Humedad Relativa: ");
Serial.print(event.relative_humidity);
Serial.println("%");
// save humidity to Adafruit IO
humidity->save(event.relative_humidity);
if(digitalRead(SENSLUZ) == LOW){
current = true;
Serial.println("Estado del clima: Soleado");
}else{
current = false;
Serial.println("Estado del clima: Nublado / Es de Noche");
}
light->save(current);
if(digitalRead(SENSLLUV) == LOW){
current1 = true;
Serial.println("Estado del clima: Está Lluviendo");
}else{
current1 = false;
Serial.println("Estado del clima: No ha Llovido");
}
rain->save(current1);
if(digitalRead(SENSHUMSUELO) == LOW){
current2 = true;
Serial.println("Estado del suelo: El suelo está empapado");
}else{
current2 = false;
Serial.println("Estado del suelo: El suelo está seco");
}
soil->save(current2);
delay(15000);
}