here’s the code:
#include <Servo.h>
#include <LiquidCrystal.h>
#include <DHT.h>
int rele=2;
int t,u,temperatura=35,intervallo=10,c0=0,c=0,c1=0,c2=0;
int m=0,h=0,g=1;
extern unsigned long timer0_millis;
DHT dht(4,DHT11);
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
Servo servomotore;
void resetMillis() {
cli();
timer0_millis = 0;
sei();
}
void setup() {
dht.begin();
lcd.begin(16, 2);
servomotore.attach(6);
pinMode(rele, OUTPUT);
Serial.begin(9600);
lcd.setCursor(7, 0);
lcd.print("tempo:");
lcd.setCursor(9, 1);
lcd.print("g");
lcd.setCursor(12, 1);
lcd.print("h");
lcd.setCursor(15, 1);
lcd.print("m");
servomotore.write(111);
}
void loop() {
delay(1000);
t=dht.readTemperature();
u=dht.readHumidity();
Serial.println("temperatura = "+String(t)+" C");
Serial.println("umidità = "+String(u)+" %");
lcd.setCursor(0, 0);
lcd.print("T= "+String(t)+"C");
lcd.setCursor(0, 1);
lcd.print("U= "+String(u)+"%");
lcd.setCursor(7, 1);
lcd.print(g);
int tempo=(millis()/1000);
if (m==0) {lcd.setCursor(13, 1);
lcd.print("0");}
if (h==0) {lcd.setCursor(10, 1);
lcd.print("0");}
if (tempo>58) {resetMillis();
m++;}
if (m>0) {lcd.setCursor(13, 1);
lcd.print(m);}
if (m>59) {m=0;
lcd.setCursor(13, 1);
lcd.print(" ");
h++;}
if (h>0) {lcd.setCursor(10, 1);
lcd.print(h);}
if (h>23) {h=0;
lcd.setCursor(10, 1);
lcd.print(" ");
g++;}
/*
if(t>temperatura){
digitalWrite(rele, HIGH);
}
else{
digitalWrite(rele, LOW);
}
if(u<40){if(c0==0){servomotore.write(80);
delay(2000);
servomotore.write(111);}
c0++;
if(c0==15){c0=0;}
}
if((u>=40)&&(u<50)){c0=0;
if(c==0){servomotore.write(80);
delay(1000);
servomotore.write(111);}
c++;
if(c==1200){c=0;}
}
if((u>=50)&&(u<55)){c=0;
if(c1==0){servomotore.write(80);
delay(500);
servomotore.write(111);}
c1++;
if(c1==600){c1=0;}
}
if((u>=55)&&(u<60)){c1=0;
if(c2==0){servomotore.write(80);
delay(200);
servomotore.write(111);}
c2++;
if(c2==300){c2=0;}
}
if(u>=60) {servomotore.write(111);
c2=0;}
*/
}
the error is every time a bit different and it happens at a random time.
i’ll add the tinkercad circuit with just the screen attached, the actual lcd screen model is 1602.
thanks for the help.