Hola estoy haciendo un controlador de acuario con las funciones basicas, que me diga la temperatura, la fecha y hora y active o desactive las luces según la hora.
El problema es que no consigo activar el rele, le pongo el codigo y no hace absolutamente nada, no se inmuta... pongo el codigo y a ver si alguien me puede ayudar y explicarme el porque, muchas gracias
codigo:
//pantalla
#include <LiquidCrystal.h>
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
//temperatura
int Temp = 0;
char Grados = 'º';
int Ana1 = A0; //Entrada analogica de LM35
int rele = 7; //rele, luces1.
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Convierte números normales decimales a BCD (binario decimal codificado)
byte decToBcd(byte val)
{
return ((val/10*16) + (val%10));
}
// Convierte BCD (binario decimal codificado) a números normales decimales
byte bcdToDec(byte val)
{
return ((val/16*10) + (val%16));
}
byte second, minute, hour, dayofweek, dayofmonth, month, year;
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second));
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
// Establece la fecha y el tiempo del ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Resetea el registro puntero
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// Alguno de estos necesitan enmascarar, ciertos bits son bits de control
*second = bcdToDec(Wire.receive()&0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive()&0x3f);
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
pinMode(rele,OUTPUT);
pinMode(13,OUTPUT);
digitalWrite(13, HIGH); //Activamos la retroiluminacion
byte second, minute, hour, dayOfMonth, month, year;
Wire.begin();
lcd.begin(16, 2);
second = 50;
minute = 59;
hour = 10;
dayOfMonth = 7;
month = 3;
year = 12;
setDateDs1307(second, minute, hour, dayOfMonth, month, year);
}
//control de las luces segun la hora:
void luces()
{
if(hour == 11 && minute == 1)
{
digitalWrite (rele, HIGH);
}
if(hour == 12 && minute == 1)
{
digitalWrite (rele, LOW);
}
}
void loop()
{
byte second, minute, hour, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfMonth, &month, &year);
lcd.setCursor (0,0);
if (dayOfMonth < 10) lcd.print("0");
lcd.print(dayOfMonth, DEC);
lcd.print("/");
if (month < 10) lcd.print("0");
lcd.print(month, DEC);
lcd.print("/");
if (year < 10) lcd.print("0");
lcd.print(year, DEC);
lcd.print(" ");
if (hour < 10) lcd.print("0");
lcd.print(hour, DEC);
lcd.print(":");
if (minute < 10) lcd.print("0");
lcd.print(minute, DEC);
{
luces();
}
//temperatura//
Temp = analogRead(Ana1); //Leemos el valor de la entrada analogica
Temp = map(Temp,0,1024,20,150); //Escalamos la señal a grados centigrados
//Mostramos los grados en el serial
Serial.print("Grados: ");
Serial.print(Temp);
Serial.print(Grados);
Serial.println("C");
//Mostramos los grados en la pantalla LCD
lcd.setCursor(0,1); //Con este comando decimos en que linea queremos escribir
lcd.print(" :Temperatura ");
lcd.setCursor(0,1);
lcd.print(Temp);
delay(10000); //Al ser temperatura no hace falta leerlo tan seguido
}