hey,i would say that i'm kinda new to arduino,i wrote 2 separate sketches to read the temperature from lm35 and one other reading the moisture level from the moisture sensor,and they are quite perfect,but when put togheter the hell begins...the moisture sensor is nice,but the lm35 says there are 20 to 47 c° x_x (that don't happend when i hold the moisture sensor in my hand tho)
my circuit is made of a rtc3231,lm35, moist capture, relè and a water pump.
#include "ora_data_temp_strings.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
//parte riguardo RTC 3231
RTC_DS3231 rtc;
DateTime now;
String stringa_ora;
String stringa_data;
int anno,mese,giorno;
int ore,minuti,secondi;
//parte riguardo lm35
float Q=5.0/1024;
float T;
float V;
int n=analogRead(A1);
LiquidCrystal_I2C lcd(0x27, 20, 4);
//parte riguardo umidità terreno
const int Aria = 585;
const int Acqua = 285;
int Hum=analogRead(0);
int Humpercento;
const int pompa = 2;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
rtc.begin();
/* settaggio manuale della data,mese,giorno,ora,minuto e secondi; */
rtc.adjust(DateTime(2021, 05, 13, 13, 36, 0));
pinMode(pompa,OUTPUT);
}
void loop() {
now = rtc.now();
ore=now.hour();
minuti=now.minute();
secondi=now.second();
anno=now.year();
mese=now.month();
giorno=now.day();
stringa_ora = elabora_stringa_ora(now);
stringa_data=elabora_stringa_data(now);
n=analogRead(A1);
V=Qn;
T=100V;
Hum=analogRead(A0);
Humpercento=map(Hum, Aria, Acqua, 0 , 100);
if(Humpercento>50)
{
digitalWrite(pompa,LOW);
}
else if(T<15)
{
digitalWrite(pompa,LOW);
}
else if(T>27)
{
digitalWrite(pompa,LOW);
}
else if(minuti>0)
{
digitalWrite(pompa,LOW);
}
else
{
digitalWrite(pompa,HIGH);
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp:");
lcd.print(T);
lcd.print((char)223);
lcd.print("c");
lcd.setCursor(0,1);
lcd.print("umidita");
lcd.print(Humpercento);
lcd.print("%");
lcd.setCursor(0,3);
lcd.print(stringa_ora);
lcd.setCursor(9,3);
lcd.print(stringa_data);
Serial.println(Humpercento);
delay(800);
}