Potentiometer interfere with the temperature

I have a project that controls a fan if the temperature rises above something
The problem is that the potentiometer interferes with the temperature reading.
I have a 4.7k pot and an lm35bt temp sensor.

The code:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
float temp;
int tempPin = A1;
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 
  // Print a message to the LCD.
  lcd.backlight();

}


void loop()
{
  temp = analogRead(tempPin);
   // read analog volt from sensor and save to variable temp
   temp = temp * 0.48828125;
   // convert the analog volt to its temperature equivalent
int  set = map(analogRead(A2), 0, 1023, 20, 66);
   
    lcd.setCursor(0,0);
  lcd.print("Temp:     ");
  lcd.print(temp);
  lcd.setCursor(0,1);
  lcd.print("Set Temp: ");
  lcd.print(set);
  delay(10);
  

  
}

And please be English friendly, I don’t know much.

  • How your potentiometer and sensor are wired?
  • Try to add additional "empty" analogRead before each use. Like:
 analogRead(tempPin);
 temp = analogRead(tempPin);
  // read analog volt from sensor and save to variable temp
  temp = temp * 0.48828125;
  // convert the analog volt to its temperature equivalent
analogRead(A2);
int  set = map(analogRead(A2), 0, 1023, 20, 66);

Thank you! It works.
Karma added!
And they are wired: They have the same 5v output, but they each have a ground, temp Is on a1 and the pot is on a2

if it really interferes it is a hardware-issue.
Anyway you should post a picture with a handdrawn schematic that shows how you have connected the LM35 and the potentiometer to the Arduino.

best regards Stefan

I hope Tiknkercad is okay..

And another question,
How do I program it to warn me when it reaches set+ 5? here is the current code:

if (temp > set && temp > warn) {
  digitalWrite(2, LOW);
  digitalWrite(10, LOW);
  tone(11,1200,200);
delay(500);
}

It doesent work

Can you give some actual examples of the interference?

Paul

rego0116:
It doesent work

What doesn’t work? In what way does it not work?

rego0116:
How do I program it to warn me when it reaches set+ 5? here is the current code:

if (temp > set && temp > warn) {

digitalWrite(2, LOW);
 digitalWrite(10, LOW);
 tone(11,1200,200);
delay(500);
}

That should work if just above there you have “warn = set + 5;”