Project 3 - Love o meter - baselinetemp variable is changing sensor value

Very simple code I posted below. Literally typed verbatim from the book. The const float baselineTemp - if I change this then the sensor val changes along with the voltage and temperature values in the serial monitor. It should have no effect on those. The wiring is good and nothing is touched when I change the baselineTemp and reupload. However the other values keep changing. Am I missing something? This topic was posted several times before without an answer.

<const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup() {
Serial.begin(9600);
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}

void loop() {
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: “);
Serial.print(sensorVal);
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(”, Volts: “);
Serial.print(voltage);
Serial.print(”, degrees C: ");
float temperature = (voltage - .5) * 100;
Serial.println(temperature);
if(temperature < baselineTemp+2){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+2 &&
temperature < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+4 &&
temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(100);
}

Please paste your code inside code tags </>
Also, please read “General Guidance and how to use the forum”…Thanks!

haroldinteractive:
Very simple code I posted below. Literally typed verbatim from the book.

It’s better if you use the code in the Examples section of the IDE…
File → Examples → 10.StarterKit_BasicKit → p03_LoveOMeter

Okay so I used the exact example code from the IDE and still this is what I got when I plugged in different values for the baselineTemp and uploaded to serial monitor. When I changed the baselineTemp and reuploaded and opened serial monitor the sensor values changed as follows:

baselineTemp / Sensor value 1 / 161 10 / 161 15 / 161 20 / 161 21 / 161 22 / 158 23 / 156 24 / 152 25 / 152 30 / 152 35 / 152 100 / 152

And after I was done I rechecked beginning values to make sure the temperature did not change. There is a change in sensor value from 21 to 24. It is so weird. Please help!

If I'm sure, the Image below, is the wiring for the project. Have you done that correctly? By the way you are using the Arduino UNO Right?

|472x500

Yes, the wiring is correct and I'm using the Arduino UNO from the Arduino starter kit. The temp sensor works and the degrees go up when I touch it but I'm still having this issue when I try to calibrate it because the baselineTemp value is directly affecting the sensor value within that range. I know it makes zero sense but I'm not alone this issue has been posted before.