sorry for the english and sorry i dont know the rules in the forum
Hello im making like a
thermostat with two ntc so i can compare the two sensors and turn on a relay when one sensor have a higher value than the other but i want to leave the "principal" board on the cave and make a simple lcd to watch the temperatures in my kitchen for example so i need to send the two ntc values to the lcd with the max485 but im a beginner in programming so i need help to understand.
Here is the code -
#include <Thermistor.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_DS1307 RTC;
#define ledProg1 13
#define ledProg2 12
unsigned long int tanterior = 0;
int tempopremido = 0;
int tempopremido2 = 0;
int tempSolar = 0;
int tempAcomu = 0;
byte botaopcoes = 2;
byte botaoMais = 3;
byte botaoMenos = 4;
byte botaoHorarios = 6;
int indicador = 0;
int anterior = HIGH;
int seta = HIGH;
int diferencialtemp = 0;
byte setpointON = 4;
byte setpointOFF = 8;
byte tempMax = 30;
byte menuSP = 100;
byte menuHorarios = 3000;
byte releSolar = 13;
byte releReserva = 11;
byte hora;
byte minutos;
byte horaoff;
byte minutosoff;
byte hora2;
byte minutos2;
byte hora2off;
byte minutos2off;
Thermistor temp(A2);
Thermistor temp2(A1);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() { //void_setup:...........................................................................................
pinMode(botaopcoes, INPUT_PULLUP);
pinMode(botaoMais, INPUT_PULLUP);
pinMode(botaoMenos, INPUT_PULLUP);
pinMode(botaoHorarios, INPUT_PULLUP);
pinMode(ledProg1, OUTPUT);
pinMode(ledProg2, OUTPUT);
lcd.begin(16, 2);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
delay(2000);
}
void loop() {
DateTime now = RTC.now();
diferencialtemp = (tempSolar) - (tempAcomu);
if (diferencialtemp <= 0) {
diferencialtemp = diferencialtemp * -1;
}
if (millis() - tanterior >= 1000) {
tanterior = millis();
tempAcomu = temp2.getTemp();
tempSolar = temp.getTemp();
lcd.setBacklight(HIGH);
lcd.setCursor(0, 0);
lcd.print("Temp. Solar:");
lcd.print(tempSolar);
lcd.setCursor(0, 1);
lcd.print("Temp. Acomu:");
lcd.print(tempAcomu);
}
//botao opções:...........................................................................................
while (digitalRead(botaopcoes) == LOW) {
delay(100);
tempopremido = tempopremido + 100;
}
if (tempopremido >= menuSP && tempopremido <= menuHorarios) {
lcd.clear();
delay(10);
}
while (tempopremido >= menuSP && tempopremido <= menuHorarios) { //menu de setpoints
lcd.setCursor(0, 0);
lcd.print("Solar.ON:");
lcd.print(setpointON);
lcd.setCursor(0, 1);
lcd.print("Sol.OFF:");
lcd.print(setpointOFF);
lcd.setCursor(11, 1);
lcd.print("DF:");
lcd.print(diferencialtemp);
indicador = digitalRead(botaopcoes);
if (indicador != anterior) {
if (seta == HIGH) {
seta = LOW;
lcd.setCursor(10, 1);
lcd.print(" ");
lcd.setCursor(11, 0);
lcd.print(char(60));
} else {
seta = HIGH;
lcd.setCursor(11, 0);
lcd.print(" ");
lcd.setCursor(10, 1);
lcd.print(char(60));
}
delay(100);
}
if (seta == LOW) {
if (digitalRead(botaoMais) == LOW) {
setpointON++;
delay(250);
}
if (digitalRead(botaoMenos) == LOW && setpointON > 0) {
setpointON--;
delay(250);
}
if (setpointON <= 9) {
lcd.setCursor(10, 0);
lcd.print(" ");
}
}
if (seta == HIGH) {
if (digitalRead(botaoMais) == LOW) {
setpointOFF++;
delay(250);
}
if (digitalRead(botaoMenos) == LOW && setpointOFF > 0) {
setpointOFF--;
delay(250);
}
if (setpointOFF <= 9) {
lcd.setCursor(9, 1);
lcd.print(" ");
}
}
esc(); //funcao para sair do menu selecionado
}
if (tempopremido >= menuHorarios) {
lcd.clear();
delay(10);
}
while (tempopremido >= menuHorarios) { //menu de temperatura maxima do termoacumolador
lcd.setCursor(0, 0);
lcd.print("TempMax.Acomula:");
lcd.setCursor(7, 1);
lcd.print(tempMax);
if (digitalRead(botaoMais) == LOW) {
tempMax++;
delay(250);
}
if (digitalRead(botaoMenos) == LOW) {
tempMax--;
delay(250);
}
if (tempMax <= 0) {
tempMax = tempMax * 0;
}
esc(); //funcao para sair do menu selecionado
}
// botao horarios:............................................................................................................
while (digitalRead(botaoHorarios) == LOW) {
tempopremido2 = tempopremido2 + 100;
delay(100);
if (tempopremido2 < menuHorarios && digitalRead(botaoHorarios) == LOW) {
digitalWrite(ledProg1, HIGH);
delay(100);
} else if (tempopremido2 > menuHorarios && digitalRead(botaoHorarios) == LOW) {
digitalWrite(ledProg2, HIGH);
delay(100);
} else {
digitalWrite(ledProg1, LOW);
digitalWrite(ledProg2, LOW);
delay(100);
}
}
//Condições para disparo da bomba:...........................................................................................
if (tempSolar > tempAcomu && diferencialtemp >= setpointON && tempAcomu <= tempMax) {
digitalWrite(releSolar, HIGH);
delay(300);
}
if (tempAcomu > tempSolar && diferencialtemp >= setpointOFF && tempAcomu <= tempMax) {
digitalWrite(releSolar, LOW);
delay(300);
}
}
void esc () { //funcao para sair do menu selecionado
if (digitalRead(botaopcoes) == LOW && digitalRead(botaoHorarios) == LOW) {
lcd.clear();
digitalWrite(ledProg1, LOW);
digitalWrite(ledProg2, LOW);
tempopremido = 0;
tempopremido2 = 0;
delay(800);
}
}