Need,my LM35 is disturbed by moisture sensor 1.1 arduino uno r3

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=100
V;

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);

}

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

You should use self-explaining names for variables, constants and functions.

n=analogRead(A1);

says nothing what this line of code does except reading in some analog value

Yu should name it like

ADC_LM35 = analogRead(LM35_Pin);

The datasheet of the LM35 says: 0 mV + 10.0 mV/°C
So this means the LM35 is an analog sensor. Analog sensors are very sensitive to EMV. It will be much easier to use a digital sensor like a DS18B20 (onewirebus) or any of the combined air-humidity and temperature-sensors that have a I2C-bus.

best regards Stefan

oh..thanks a lot for the info,i didn't figured out how to copy for the forum x.x
about the n= that's how my teacher explained me to do that one
another question...what does EMV stands for? googling for it i found somethings like "europay,mastercard and visa circuit" guess that's not correct

Hello
take a view here for a sensor using the I²C interface.

https://www.arduino.cc/reference/en/libraries/bme280/

paulpaulson]

Hello
take a view here for a sensor using the I²C interface.

BME280 - Arduino Reference]

i don't want to underestimate my self,but i think that's way too hard for me to even barely understand ^^'' that's the first "year" of school i study arduino and i have my own arduino uno from like a week or so x_x
the only real reason for why i can "write" a sketch (yeah is bad and maybe it need many adjustments) is cause i made some stupid c++ and assembly programs at school

sorry that's a german abbreviation. In english EMI electro-magnetic-interference or electromagnetic noise.

if your teacher told you to code that way. Your teacher might be a teacher for geography or biology and knowing a lot of things in that field but he is the most bloodiest newbee about software-developing. If he is teaching programming for several years he is the most successfull ignorant to software-development basics. OMG.

take a look at these two functions that do the same thing


int ABC (unsigned long &D, unsigned long E) {
  unsigned long Z  = millis();  
  if ( Z - D >= E )
  {
    D = Z; 
    return 1;
  } 
  else return 0;
}



boolean TimePeriodIsOver (unsigned long &periodStartTime, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();  
  if ( currentMillis - periodStartTime >= TimePeriod )
  {
    periodStartTime = currentMillis; // set new expireTime
    return true;                // more time than TimePeriod) has elapsed since last time if-condition was true
  } 
  else return false;            // not expired
}

I'm very sure after reading the first one you quickly jumped over to the second
and immediately get at least a glimpse of what the purpose of this function is.

The second function is much easier to understand because all and every variable has a self-explaining name and some additional comments.

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

1 Like

Which humidity sensor do you use ?

The LM35 is to learn and see that it works. If it works then you should put it aside and get something better. We all have been there (maybe not all of us, but I guess half of us).

The LM35 outputs a real voltage and the Arduino in default mode measures a voltage relative to the 5V. If the 5V drops, then the Arduino thinks that the temperature rises.
As @StefanL38 mentioned, noise from the circuit will influence the temperature measurements.

The BME280 can measure the temperature and humidity in a accurate way. Take care that it is a 3.3V sensor. If you have a Arduino Uno, then you have a 5V Arduino board.
Adafruit makes modules that are compatible with 3.3V and 5V Arduino boards: https://www.adafruit.com/product/2652.
There are between 5 and 10 good sensors which are used with Arduino. Here is another one.
The LM35, TMP36, DHT11, DHT22 are not good sensors.

A quick fix could be to use the 3.3V as shown here: https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor#getting-better-precision-2933885-7. You also have to take the average of many samples to get rid of noise.

A post was split to a new topic: I am trying to interface LM35 temperature sensor and soil moisture sensor

for humidity i mean of the soil D:
actually i bought a kit on amazon and is capacitative moisture sensor 1.2 (or 1.1 don't remember) is kinda cheap,and after i gave a try to the dht11 i also had,now everything works well...now a new problem appeared,but i guess i'll leave it for another topic

Are the wires for the LM35 laying in water at all? If they get wet, the damn things go bananas. (Been there, pulled out hair.)

-jim lee