Buenas tardes, tengo montado el funduino, el lcd y la temperatura funciona muy bien, pero no se como conectar correctamente el rele y como hacer el dimeo (del cual tengo el codigo pero cuando conecto los cables no enciende nada). Hasta el domingo no podre revisar todo el cableado, pero creo que el problema estará en el código, ya que he estado copiando y pegando mucho y haciendo pruebas, pero ahora mismo no doy con la solución, y de paso me gustaria que alguien lo revisase por si hay algo que pudiese dar problemas.
Tengo conectado el pin del dimeo al 8 ANALOG (ni PWN ni DIGITAL) y el rele tengo puestos los cables en los extremos, segun lo veo, continuando con el dibujo del esquema.
Codigo "malo" con errores
Por favor, que alguien me diga algo en cuanto puedan.
Muchas gracias de antemano.
SOLUCIÓN con el Codigo bien, aun asi hay cositas comentadas que son pruebas y demas que hago con el bichejo xD
Tengo conectado el pin del dimeo al 8 ANALOG (ni PWN ni DIGITAL) y el rele tengo puestos los cables en los extremos, segun lo veo, continuando con el dibujo del esquema.
Codigo "malo" con errores
PHP:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h" // Incluye la librería RTClib
RTC_DS1307 RTC; // Crea el objeto RTC
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int Retraso=5000;
int RelayPin = 2;
int bolRele1=0;//0=no 1=si
int bolRele2=0;//0=no 1=si
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup()
{
// start serial port
// Serial.begin(9600);
lcd.init();
Serial.begin(9600); // Establece la velocidad de datos del puerto serie
Wire.begin(); // Establece la velocidad de datos del bus I2C
RTC.begin(); // Establece la velocidad de datos del RTC
lcd.backlight();
// Start up the library
sensors.begin();
pinMode(RelayPin, OUTPUT); //Inicialitzem el pin del rele
}
int minuts;
int hora;
void loop()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
DateTime now = RTC.now(); // Obtiene la fecha y hora del RTC
lcd.setCursor(0,0);
lcd.print("=====ADRIA GRAU=====");
lcd.setCursor(0,1);
lcd.print("Temperatura: ");
sensors.requestTemperatures(); // Send the command to get temperatures
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(0,2);
lcd.print("Hora: ");
lcd.print(now
.hour());
lcd.print(":");
lcd.print(now.minute());
lcd.print(":");
lcd.print(now.second());
lcd.print(" ");
delay(2000);
//CODIC PER A VOLTATGE LEDS
minuts=now.minute();
hora=now.hour();
Luces(minuts, hora);
//if (now.minute < 2) Retraso=1000;
///else if (now.hour < 5) Retraso=10000;
//else Retraso=3000;
Retraso=3000;
}
void Luces(int minutos, int horas) {
//LUCES PRIMARIAS//
int LucesAzules;
int InicioAmanecerAzul=540;//09:00 /conversion seria 60x11=660 la misma tabla para los demas parametros //
int FinAmanecerAzul=600;//12:00 //
int InicioAnochecerAzul=1080;//19:00//
int FinAnochecerAzul=1140;//18:00//
int MaxAzul=250;
int PorcentAzules;
int Tiempo;
Tiempo=horas*60+minutos;
//Activem el rele de la llum
if (Tiempo>540 && bolRele1==0)
{
digitalWrite(2, HIGH);
bolRele1=1;
}
if (Tiempo>1140 && bolRele1==1)
{
digitalWrite(2, LOW); //CODIC PER A POSSAR EN MARXA EL RELE
bolRele1=0;
}
//if (Tiempo < 60)Tiempo=Tiempo+1440;
//Tiempo=Tiempo-60; //Horario de Invierno
//################################# AZULES ###################################
//Noche
if (Tiempo < InicioAmanecerAzul) LucesAzules=0;
//Amanecer
if (Tiempo >= InicioAmanecerAzul && Tiempo <= FinAmanecerAzul) LucesAzules=(Tiempo-InicioAmanecerAzul)*4;
//Dia
if ((Tiempo > FinAmanecerAzul) && Tiempo < InicioAnochecerAzul) LucesAzules=MaxAzul;
//Anochecer
if (Tiempo >= InicioAnochecerAzul && Tiempo <= FinAnochecerAzul) LucesAzules=(FinAnochecerAzul-Tiempo)*4;
//Control
if( LucesAzules <0) LucesAzules=0;
if( LucesAzules >250) LucesAzules=250;
analogWrite(8, 255-LucesAzules );
//analogWrite(10, 255-LucesBlancas);
PorcentAzules =Porcent(LucesAzules ,255)*2;
p();
//FadeLcd();
//lcd.init();
lcd.setCursor(0,3);
//if (PorcentAzules < 10);
lcd.print("% ");
Serial.print(PorcentAzules);
lcd.print(PorcentAzules);
lcd.print(" ");
if (LucesAzules > 1)
{
// digitalWrite(2, HIGH); //CODIC PER A POSSAR EN MARXA EL RELE
lcd.print(" " );
lcd.print(bolRele1);
}
else
{
//digitalWrite(2, LOW);
lcd.print(" ILUMINACIO OFF"); //CODIC PER A TALLAR EL RELE
}
}
//PAUSAR 3 SEGONS
void p ()
{
delay (3000);
}
int Porcent(int Valor, int Maximo)
{
int result;
result=Valor*50;
result=result/Maximo;
return result;
}
Por favor, que alguien me diga algo en cuanto puedan.
Muchas gracias de antemano.
SOLUCIÓN con el Codigo bien, aun asi hay cositas comentadas que son pruebas y demas que hago con el bichejo xD
PHP:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h" // Incluye la librería RTClib
RTC_DS1307 RTC; // Crea el objeto RTC
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int Retraso=5000;
int RelayPin = 2;
int bolRele1=0;//0=no 1=si
int bolRele2=0;//0=no 1=si
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup()
{
// start serial port
// Serial.begin(9600);
lcd.init();
Serial.begin(9600); // Establece la velocidad de datos del puerto serie
Wire.begin(); // Establece la velocidad de datos del bus I2C
RTC.begin(); // Establece la velocidad de datos del RTC
lcd.backlight();
// Start up the library
sensors.begin();
pinMode(RelayPin, OUTPUT); //Inicialitzem el pin del rele
}
int minuts;
int hora;
void loop()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
DateTime now = RTC.now(); // Obtiene la fecha y hora del RTC
lcd.setCursor(0,0);
lcd.print("=====ADRIA GRAU=====");
lcd.setCursor(0,1);
lcd.print("Aigua: ");
sensors.requestTemperatures(); // Send the command to get temperatures
lcd.print(sensors.getTempCByIndex(0));
lcd.print(" C");
lcd.setCursor(0,2);
lcd.print("Hora: ");
lcd.print(now
.hour());
lcd.print(":");
lcd.print(now.minute());
// lcd.print(":");
// lcd.print(now.second());
// lcd.print(" ");
// delay(2000);
//CODIC PER A VOLTATGE LEDS
minuts=now.minute();
hora=now.hour();
Luces(minuts, hora);
//if (now.minute < 2) Retraso=1000;
///else if (now.hour < 5) Retraso=10000;
//else Retraso=3000;
// Retraso=3000;
}
void Luces(int minutos, int horas) {
//LUCES PRIMARIAS//
int LucesAzules;
int LucesBlancas;
int InicioAmanecerBlanco=600;
int InicioAmanecerAzul=601;//09:00 /conversion seria 60x11=660 la misma tabla para los demas parametros //
int FinAmanecerBlanco=660;
int FinAmanecerAzul=661;//12:00 //
int InicioAnochecerBlanco=1195;
int InicioAnochecerAzul=1200;//19:00//
int FinAnochecerBlanco=1255;
int FinAnochecerAzul=1260;//18:00//
int MaxBlanco=250;
int MaxAzul=250;
int PorcentBlancas;
int PorcentAzules;
int Tiempo;
Tiempo=horas*60+minutos;
//ACTIVA EL RELE DE LA LLUM
if (Tiempo>601 && bolRele1==0)
{
digitalWrite(2, HIGH);
bolRele1=1;
lcd.backlight();
}
if (Tiempo>1265 && bolRele1==1)
{
digitalWrite(2, LOW); //CODIC PER A POSSAR EN MARXA EL RELE
bolRele1=0;
lcd.noBacklight();
}
//if (Tiempo < 60)Tiempo=Tiempo+1440;
//Tiempo=Tiempo-60; //Horario de Invierno
//################################# AZULES ###################################
//Noche
if (Tiempo < InicioAmanecerBlanco) LucesBlancas=0;
//Amanecer
if (Tiempo >= InicioAmanecerBlanco && Tiempo <= FinAmanecerBlanco) LucesBlancas=(Tiempo-InicioAmanecerBlanco)*4;
//Dia
if ((Tiempo > FinAmanecerBlanco) && Tiempo < InicioAnochecerBlanco) LucesBlancas=MaxBlanco;
//Anochecer
if (Tiempo >= InicioAnochecerBlanco && Tiempo <= FinAnochecerBlanco) LucesBlancas=(FinAnochecerBlanco-Tiempo)*4;
//################################# BLANCAS ###################################
//Noche
if (Tiempo < InicioAmanecerAzul) LucesAzules=0;
//Amanecer
if (Tiempo >= InicioAmanecerAzul && Tiempo <= FinAmanecerAzul) LucesAzules=(Tiempo-InicioAmanecerAzul)*4;
//Dia
if ((Tiempo > FinAmanecerAzul) && Tiempo < InicioAnochecerAzul) LucesAzules=MaxAzul;
//Anochecer
if (Tiempo >= InicioAnochecerAzul && Tiempo <= FinAnochecerAzul) LucesAzules=(FinAnochecerAzul-Tiempo)*4;
//Control
if( LucesAzules <0) LucesAzules=0;
if (LucesBlancas<0) LucesBlancas=0;
if( LucesAzules >250) LucesAzules=250;
if(LucesBlancas>250) LucesBlancas=250;
analogWrite(8, LucesAzules );
analogWrite(9, LucesBlancas);
PorcentAzules =Porcent(LucesAzules ,255)*2;
PorcentBlancas =Porcent(LucesBlancas, 255)*2;
p();
lcd.setCursor(0,3);
//Serial.print(PorcentAzules);
lcd.print(PorcentAzules);
lcd.print("%");
lcd.print(" - ");
//lcd.print("% ");
//Serial.print(PorcentBlancas);
lcd.print(PorcentBlancas);
lcd.print("%");
//lcd.print(" - ");
//lcd.print(Tiempo);
if (LucesAzules > 1)
{
// digitalWrite(2, HIGH); //CODIC PER A POSSAR EN MARXA EL RELE
//lcd.print(" " );
//lcd.print(bolRele1);
}
else
{
//digitalWrite(2, LOW);
//lcd.print(" ILUMINACIO OFF"); //CODIC PER A TALLAR EL RELE
}
// lcd.clear();
}
//PAUSAR 3 SEGONS
void p ()
{
delay (6000);
}
int Porcent(int Valor, int Maximo)
{
int result;
result=Valor*50;
result=result/Maximo;
return result;
}
Última edición: