Temperature Sensor in my Arduino UNO set

My temperature sensor has a hard time recording changes in temperature. However, when changes in temperature occurs the sensor value readings change. Due to this I know it works. So how can I make my temperature sensor record temperature changes with more precision?

I really hope that you guys can give me your thoughts on solutions to this problem I'am having with my temperature sensor. Also,the type of temperature sensor I have is a "36GZ".

const int sensorPin = A0;
const float baselineTemp = 23.0;
const int ledPin = 8;
int notes[] = {262,295};
float voltage;
void setup() {
Serial.begin(9600);
for(int pinNumber = 5; pinNumber<6; pinNumber++){
  pinMode(pinNumber,OUTPUT);
  digitalWrite(pinNumber, LOW);
 }
}
void loop() {
int sensorVal = analogRead(sensorPin);
Serial.print(", degrees C: ");
float temperature = (voltage - 0.5) * 100;
Serial.println(temperature);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
delay(1000);
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(", Volts: ");
Serial.print(voltage);
if(temperature < baselineTemp){
  noTone(8);
  digitalWrite(5, LOW);
} 
else if(temperature >= baselineTemp && temperature < baselineTemp+2){
  tone(8, notes[0]);
  digitalWrite(5, HIGH);
}
else if (temperature >= baselineTemp+2 && temperature <= baselineTemp+4){
  tone(8, notes[1]);
  digitalWrite(5, LOW);
}
}

Schematic 1 modified.PNG

Please read the sticky posts at the top of the forum especially this one

Then add your sketch and schematic please as well as the type of sensor being used.

Your issue does not have enough detail to give a better answer.

Bob.

My temperature sensor has a hard time recording changes in temperature. However, when changes in temperature occurs the sensor value readings change. Due to this I know it works. So how can I make my temperature sensor record temperature changes with more precision?

I really hope that you guys can give me your thoughts on solutions to this problem I'am having with my temperature sensor.

hasiru:
My temperature sensor has a hard time recording changes in temperature. However, when changes in temperature occurs the sensor value readings change. Due to this I know it works. So how can I make my temperature sensor record temperature changes with more precision?

I really hope that you guys can give me your thoughts on solutions to this problem I'am having with my temperature sensor.

You said that already. Then you were asked for more information. Why did you just recopy your post instead of adding the requested detail?

for(int pinNumber = 5; pinNumber<6; pinNumber++){
  pinMode(pinNumber,OUTPUT);
  digitalWrite(pinNumber, LOW);
 }

Why the for loop? Why not just:

  pinMode(5,OUTPUT);
  digitalWrite(5, LOW);
int sensorVal = analogRead(sensorPin);
Serial.print(", degrees C: ");
float temperature = (voltage - 0.5) * 100;

You're using voltage BEFORE you give it a value?

float voltage = (sensorVal/1024.0) * 5.0;

Don't you already have a global variable named voltage? Why are you creating a second one? That's going to get really confusing having two variables in different scope with the same name. Why are you putting the value in this one that's local to loop and then never using it? You know this one loses it's value every time loop repeats. I would use the global one.

Think your schem shows a speaker and an LED.
There is nothing on your schem showing anything connected to A0 yet your sketch seems to call it ?
You call pin D8 for the LED in the sketch and your schem has it on D3.

With so many errors between the schem and the sketch you may want to go back to some basics first.
re-check you have each item on the correct pins and update your schem to reflect what you really have on those pins.

BTW there is no need to break out the sketch like that as I am sure it would fit between a single set of code tags.

We also still need to know what type of temperature sensor you have too.

Bob.