Go Down

Topic: Temperature Sensor in my Arduino UNO set (Read 205 times) previous topic - next topic

hasiru

Jul 31, 2019, 05:26 am Last Edit: Aug 02, 2019, 06:52 am by hasiru Reason: I need to upload an image of my creation and a schematic.
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".




Code: [Select]
const int sensorPin = A0;
const float baselineTemp = 23.0;
const int ledPin = 8;
int notes[] = {262,295};
float voltage;

Code: [Select]
void setup() {
Serial.begin(9600);
for(int pinNumber = 5; pinNumber<6; pinNumber++){
  pinMode(pinNumber,OUTPUT);
  digitalWrite(pinNumber, LOW);
 }
}

Code: [Select]
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);

Code: [Select]

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






ballscrewbob

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.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

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.

Delta_G

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?



Code: [Select]
for(int pinNumber = 5; pinNumber<6; pinNumber++){
  pinMode(pinNumber,OUTPUT);
  digitalWrite(pinNumber, LOW);
 }


Why the for loop?  Why not just:


Code: [Select]

  pinMode(5,OUTPUT);
  digitalWrite(5, LOW);
 



Code: [Select]
int sensorVal = analogRead(sensorPin);
Serial.print(", degrees C: ");
float temperature = (voltage - 0.5) * 100;


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

Code: [Select]

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. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

ballscrewbob

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.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Go Up