/**
Basic NTC Thermistor demo
https://wokwi.com/arduino/projects/299330254810382858
Assumes a 10K@25℃ NTC thermistor connected in series with a 10K resistor.
Copyright (C) 2021, Uri Shaked
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
const float BETA2 = 3950;
//const float celsius2 = 0;
const int pompa = 6;
const int su = 7;
const int giu = 8;
const int ok = 9;
const int indietro = 10;
const int menu = 13;
const int accensione = 15;
const int candeletta = 16;
const int termostato = 18;
int varpompa = 0;
int varsu = 0;
int vargiu = 0;
int varok = 0;
int varindietro = 0;
int varmenu = 0;
int on = LOW;
int acceso = 0;
int term = 0;
//int candeletta = 0;
void setup() {
pinMode (accensione, INPUT);
pinMode (termostato, INPUT);
pinMode (candeletta, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() { //da rivedere
term = digitalRead(termostato);
if (term == HIGH)
{
poweron: //accensione
int analogValue2 = analogRead(A3);
float celsius2 = 1 / (log(1 / (1023. / analogValue2 - 1)) / BETA2 + 1.0 / 298.15) - 273.15;
/*Serial.print("Temperature: ");
Serial.print(celsius2);
Serial.println(" ℃");*/
on = digitalRead(accensione);
while (celsius2<= 50)
{
if (on == HIGH)
{
digitalWrite (candeletta, HIGH );
int analogValue2 = analogRead(A3);
float celsius2 = 1 / (log(1 / (1023. / analogValue2 - 1)) / BETA2 + 1.0 / 298.15) - 273.15;
on = LOW ;
delay(50);
/*Serial.print("Temperature: ");
Serial.print(celsius2);
Serial.println(" ℃");*/
}
else
{
// on = LOW ;
goto poweron;
}
}
/*while (on == 0 )
{
on = digitalRead(accensione);
if (on == HIGH )
{digitalWrite (candeletta, HIGH );}
}*/
temp:
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(8, 0);
lcd.print(" ");
varmenu = digitalRead(menu);
if (varmenu == HIGH)
{
varindietro = 0;
while (varindietro == 0)
{
lcd.setCursor(1, 0);
lcd.print("temperatura");
varindietro = digitalRead(indietro);
varmenu = 0;
varsu = digitalRead(su);
vargiu = digitalRead(giu);
if (varsu == HIGH)
{goto pippo;}
}
}
on = digitalRead(accensione);
if (on == HIGH )
{digitalWrite (candeletta, HIGH );}
else
{digitalWrite (candeletta, LOW );}
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
lcd.setCursor(1, 0);
lcd.print(celsius);
lcd.write(0xdf);
lcd.print("C");
if (celsius>= 45)
{
digitalWrite(pompa, HIGH);
}
else
{
digitalWrite(pompa, LOW);
}
delay(1000);
goto temp;
pippo: // gestione con salto
varindietro = 0;
while (varindietro == 0)
{
lcd.setCursor(0, 1);
lcd.print("ivano");
varindietro = digitalRead(indietro);
varmenu = 0;
varsu = digitalRead(su);
vargiu = digitalRead(giu);
}
}
}
/*#include <LiquidCrystal.h>
float Vin=5.0; // [V]
float Rt=10000; // Resistor t [ohm]
float R0=10000; // value of rct in T0 [ohm]
float T0=298.15; // use T0 in Kelvin [K]
float Vout=0.0; // Vout in A0
float Rout=0.0; // Rout in A0
// use the datasheet to get this data.
float T1=273.15; // [K] in datasheet 0º C
float T2=373.15; // [K] in datasheet 100° C
float RT1=35563; // [ohms] resistence in T1
float RT2=549; // [ohms] resistence in T2
float beta=0.0; // initial parameters [K]
float Rinf=0.0; // initial parameters [ohm]
float TempK=0.0; // variable output
float TempC=0.0; // variable output
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
lcd.begin(16,2);
pinMode(0, INPUT);
//parâmetros
beta=(log(RT1/RT2))/((1/T1)-(1/T2));
Rinf=R0*exp(-beta/T0);
}
void loop()
{
Vout=Vin*((float)(analogRead(0))/1024.0); // calc for ntc
Rout=(Rt*Vout/(Vin-Vout));
TempK=(beta/log(Rout/Rinf)); // calc for temperature
TempC=TempK-273.15;
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.setCursor(0,1);
lcd.print(TempC);
lcd.write(0xdf); // to display °
lcd.print("C ");
lcd.print((TempC * 9)/5 + 32); // C to F
lcd.write(0xdf);
lcd.print("F");
delay(1200);
}
*/