Buenas! Me presento en el foro! primero de todo agradeceros vuestra atención, os comento cuál es mi proyecto.
He encontrado muchos proyectos de control de acuarios pero poco para terrarios, y menos que controlen diferentes temperaturas entre la noche y el día.
Con mis escasos conocimientos he intentado crear el código pero me aparecen varios errores que no se solucionar.
Primero de todo os describo el material que voy a utilizar:
- Arduino Mega 2560
- Sensores de temperatura (Uno en cada terrario) DS1820
- Sensor de humedad. DHT22 (La humedad no se tiene que controlar de una manera tan precisa como pasa con la temperatura.)
- Reloj DS3231 o el que me recomendeis
- Placa rele de 8 canales
- Pantalla lcd full graphics smart controller (muy utilizada en las impresoras 3D)
Funciones a conseguir:
- Controlar temperatura diurna y nocturna (pudiendo establecer esta temperatura para cada caso)
- Que se encienda o apague una bombilla cerámica calefactora si la temperatura desciende.
- Encender y apagar las luces según la hora que sea.
- Informar de la humedad
- Mostrar en pantalla los valores y poder ajustar desde la misma pantalla la temperatura a la que se quiere mantener el terrario. En el caso que haya que cambiarlas.
Espero podáis ayudarme, mi intención es publicar las instrucciones y todos los pasos, no solo el firmware sino también el montaje. Y compartirlo con otros aficionados que se que también necesitan una solución y que por su falta de conocimientos acaban comprando sistemas mucho más caros y con menos funcionalidades.
Espero no haber olvidado nada.
/*DENDRUINO CONTROL V1.0/
/*------------------ LIBRARIES ------------------*/
#include <DallasTemperature.h>
#include <OneWire.h>
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
/*------------------ PIN ------------------*/
#define TEMP 2 // PIN SENSORES TEMPERATURA
//#define SENSOR HUMEDAD FALTA DECIDIR SENSOR HUMEDAD Y PIN
#define LUZDIA 3 // LUZDIA DE TERRARIO 1 Y 2 SE ENCIENDEN A LA VEZ
#define LUZNOCHE 4 // LUZNOCHE DE TERRARIO 1 Y 2 SE ENCIENDEN A LA VEZ
#define CABLE1 5
#define CERAMICA1 6
#define VENTILACON1 7
#define CABLE2 8
#define CERAMICA2 9
#define VENTILACON2 10
/*------------------ LCD ------------------*/
LiquidCrystal_I2C lcd(0x27,20,4);
OneWire oneWire(TEMP);
DallasTemperature sensors(&oneWire);
DeviceAddress TERRARIO1, TERRARIO2;
RelojDS1307Class Reloj;
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
/*------------------ RELES ACTIVOS ------------------*/
pinMode(LUZDIA, OUTPUT); //LUZDIA TERRARIO 1 Y 2 CONECTADOS AL MISMO RELE
pinMode(LUZNOCHE, OUTPUT); //LUZNOCHE TERRARIO 1 Y 2 CONECTADOS AL MISMO RELE
pinMode(CABLE1, OUTPUT);
pinMode(CERAMICA1, OUTPUT);
pinMode(VENTILACON1, OUTPUT);
pinMode(CABLE2, OUTPUT);
pinMode(CERAMICA2, OUTPUT);
pinMode(VENTILACON2, OUTPUT);
Serial.print("Localizando sondas de temperatura: ");
Serial.print("Encontradas ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" sondas.");
lcd.setCursor(4,0);
lcd.print("DENDRUINO CONTROL");
lcd.setCursor(5,2);
lcd.print("V 1.0");
delay(5000);
//Reloj.SetDateTime( 17, 04, 13, 20, 47, 00 );
}
void loop()
{
Serial.print("Recibiendo temperaturas...");
sensors.requestTemperatures();
Serial.println("OK");
printData(TERRARIO1);
printData(TERRARIO2);
float TEMP1 = sensors.getTempC(TERRARIO1); // TEMP1=SENSOR DE TEMPERATURA TERRARIO 1
float TEMP2 = sensors.getTempC(TERRARIO2); // TEMP2=SENSOR DE TEMPERATURA TERRARIO 2
/*------ AJUSTES DE TEMPERATURA Y HORARIO DE CADA TERRARIO ------*/
//TEMPERATURA DIURNA
// ---TERRARIO 1 (26 grados de 9.00-21.00)-----------------
if(TEMP1 < 25.5 && Reloj.IsLater(8, 59) && Reloj.IsPrevious(20, 59)) //TEMPERATURA ENCENDIDO
{
digitalWrite (CABLE1, HIGH);
digitalWrite (CERAMICA1, HIGH);
lcd.setCursor(19,2);
lcd.print("ON");
}
if(TEMP1 > 26 && Reloj.IsLater(8, 59) && Reloj.IsPrevious(20, 59)) //TEMPERATURA APAGADO
{
digitalWrite (CABLE1, LOW);
digitalWrite (CERAMICA1, LOW);
lcd.setCursor(19,2);
lcd.print("OFF");
}
// ---TERRARIO 2 (26 grados de 9.00-21.00)-----------------
if(TEMP2 < 25.5 && Reloj.IsLater(8, 59) && Reloj.IsPrevious(20, 59)) //TEMPERATURA ENCENDIDO
{
digitalWrite (CABLE2, HIGH);
digitalWrite (CERAMICA2, HIGH);
lcd.setCursor(19,3);
lcd.print("ON");
}
if(TEMP2 > 26 && Reloj.IsLater(8, 59) && Reloj.IsPrevious(20, 59)) //TEMPERATURA APAGADO
{
digitalWrite (CABLE2, LOW);
digitalWrite (CERAMICA2, LOW);
lcd.setCursor(19,3);
lcd.print("OFF");
}
//TEMPERATURA NOCTURNA
// ---TERRARIO 1 (23 grados de 21.00-9.00)-----------------
if(TEMP1 < 23 && Reloj.IsLater(20, 59) && Reloj.IsPrevious(8, 59)) //TEMPERATURA ENCENDIDO
{
digitalWrite (CABLE1, HIGH);
digitalWrite (CERAMICA1, HIGH);
lcd.setCursor(19,2);
lcd.print("ON");
}
if(TEMP1 > 23.5 && Reloj.IsLater(20, 59) && Reloj.IsPrevious(8, 59)) //TEMPERATURA APAGADO
{
digitalWrite (CABLE1, LOW);
digitalWrite (CERAMICA1, LOW);
lcd.setCursor(19,2);
lcd.print("OFF");
}
// ---TERRARIO 2 (23 grados de 21.00-9.00)-----------------
if(TEMP2 < 23 && Reloj.IsLater(20, 59) && Reloj.IsPrevious(8, 59)) //TEMPERATURA ENCENDIDO
{
digitalWrite (CABLE2, HIGH);
digitalWrite (CERAMICA2, HIGH);
lcd.setCursor(19,3);
lcd.print("ON");
}
if(TEMP2 > 23.5 && Reloj.IsLater(20, 59) && Reloj.IsPrevious(8, 59)) //TEMPERATURA APAGADO
{
digitalWrite (CABLE2, LOW);
digitalWrite (CERAMICA2, LOW);
lcd.setCursor(19,3);
lcd.print("OFF");
}
/*--------------- AJUSTES ILUMINACION ---------------*/
// LAS LUCES DE TERRARIO 1 Y 2 ESTAN CONECTADOS AL MISMO RELE SE ENCENDERAN Y APAGAR AL MISMO TIEMPO
// LUZ DIURNA DE 9.00 A 21.00
// LUZ NOCTURNA DE 21.00 A 9.00
if(Reloj.IsLater(8, 59) && Reloj.IsPrevious(20, 59))
{
digitalWrite(LUZDIA, HIGH);
digitalWrite(LUZNOCHE, LOW);
}
else
{
digitalWrite(LUZDIA, LOW);
digitalWrite(LUZNOCHE, HIGH);
}
/*--------------- VERIFICACION SONDAS FUNCIONANDO ---------------*/
// SI LAS SONDAS FUNCIONAN MARCA LAS SONDAS CON (OK)
if (!sensors.getAddress(TERRARIO1, 0))
{
Serial.println("INCAPAZ DE ENCONTRAR SONDA TERRARIO 1");
lcd.setCursor(0,1);
lcd.print("FALLO TEMP1"); //FALLO SENSOR TEMPERATURA 1
}
if (sensors.getAddress(TERRARIO1, 0))
{
lcd.setCursor(0,1);
lcd.print("TEMP1 -- OK");
}
if (!sensors.getAddress(TERRARIO2, 1))
{
Serial.println("INCAPAZ DE ENCONTRAR SONDA TERRARIO 2");
lcd.setCursor(10,1);
lcd.print("FALLO TEMP2"); //FALLO SENSOR TEMPERATURA 2
}
if (sensors.getAddress(TERRARIO2, 1))
{
lcd.setCursor(10,1);
lcd.print("TEMP2 -- OK");
}
void printTemperature(DeviceAddress deviceAddress)
{
float TEMP1 = sensors.getTempC(TERRARIO1);
float TEMP2 = sensors.getTempC(TERRARIO2);
Serial.print("TERRARIO 1: ");
Serial.print(TEMP1);
Serial.print(" ");
Serial.print("TERRARIO 2: ");
Serial.print(TEMP2);
Serial.print(" ");
lcd.setCursor(0,0);
lcd.print(Reloj.DateTime());
lcd.setCursor(0,2);
lcd.print("TERRARIO 1: ");
lcd.print(TEMP1);
lcd.setCursor(0,3);
lcd.print("TERRARIO 2: ");
lcd.print(TEMP2);
}