potentiometer changes lm35 sensor value

hello I'm doing a greenhouse but I have a problem some sensors change the measurements of other sensors

I'll give you this example I'm using the potentiometer instead of photoresistor
when the potentiometer value changes also the reading of a temperature sensor changes

void setup()


{
 Serial.begin(9600);

}

void loop ()                             

{
 {  // potentiometer:
 int sensorValue1 = analogRead(A2);
 // print out the value you read:
 Serial.println(sensorValue1);
 delay(100);
}
{// lm35: 
int sensorValue = analogRead(A0);
Serial.println(sensorValue);

 Serial.print("Analog = ");
 Serial.print(sensorValue);

 float tempC = sensorValue * 0.48875;

 Serial.print("     Temp = ");
 Serial.println(tempC);
 delay(1000); }

 
{ // lm35:
 int sensorValue2 = analogRead(A1);
Serial.println(sensorValue2);

 Serial.print("Analog = ");
 Serial.print(sensorValue2);

 float tempC2 = sensorValue2 * 0.48875;

 Serial.print("     Temp1 = ");
 Serial.println(tempC2);
 delay(1000); }

}

when the potentiometer is 0 the values are correct

Analog = 46 Temp = 22.48
Analog = 47 Temp1 = 22.97
0
Analog = 46 Temp = 22.48
Analog = 47 Temp1 = 22.97
0
Analog = 46 Temp = 22.48
Analog = 47 Temp1 = 22.97
0
Analog = 47 Temp = 22.97
Analog = 47 Temp1 = 22.97
0

, but when i change the potentiometer value to 1023
the sensor values are incorrect
1022
Analog = 77 Temp = 37.63
Analog = 47 Temp1 = 22.97
1021
Analog = 73 Temp = 35.68
Analog = 47 Temp1 = 22.97
1023
Analog = 78 Temp = 38.12
Analog = 46 Temp1 = 22.48
1023

I do not want the temperature to change when the potentiometer value changes

eww.ino (754 Bytes)

Welcome to the forum! Please edit you post to include code tags. See How to use the forum. Also, post a schematic because I doubt the problem is in code :wink:

And extra tips:

  • A float isn't simply a decimal point :wink:
  • Use variable names for pins (like cont byte TempSensorPin). Makes the code more readable and easier to change.
  • Once you start numbering variables => arrays! :wink:

the connections are right I have checked so many times

Hi,
What arduino are you using?
How many channels are you using?
How are you connecting them?
Regards

I'm using arduino uno and I'm using A0 A1 A2 channels and connect them through the breadboard

Read your analogue inputs twice; discard the first reading.

Does it change the behaviour?

analogRead(A2);
int sensorValue1 = analogRead(A2);
Serial.println(sensorValue1);

repeat for other inputs

it works thanks a lot