Go Down

Topic: Temperature Sensor (Read 142 times) previous topic - next topic

jmetz

Good morning,
I am working on a project that uses the temperature sensor. It's set up with 3 LED lights that turn on when the temperature is 2, 4, and 6+ degrees above the baseline temp. However, I am having trouble setting the baseline. When I first open the serial monitor to see the temp in open air, picture 1 are the readings I was getting. So I set the baseline temp at 23 degrees. When I uploaded the code and put my finger on the sensor, the temps jumped way up as seen is picture 2. So I let the sensor sit a few minutes to see what it would go back down to in open air. It only dropped to the low 50s and never got anywhere near 23 again. So I reset the baseline at 51, uploaded the code again, and put my finger on the sensor. The readings were back down in the 20s.

I cannot figure out how to get consistent readings. Is there a conversion happening that I am unaware of? Or am I reading the baseline wrong?

Any help is appreciated. Thanks!

pylon

A link to the datasheet of the used sensor would help, a wiring diagram too and we might need the used source code (don't forget the code tags!).

jmetz

I am completely new to using the arduino. How do I get the datasheet for the used sensor? The wiring diagram is below. And what is the source code and code tags?

pylon

Quote
How do I get the datasheet for the used sensor?
That's the manual of the sensor. The vendor of the sensor should provide that information. If you don't got it, it may help to tell us what exact type of sensor you're using.

Quote
And what is the source code and code tags?
The source code is all the text (statements, variable declarations, etc.) that is used to build your sketch, the program that runs on the Arduino.
Code tags are used in this forum system to mark source code. Without them the forum system interprets some character combinations specially and the code gets hard to read. The button in the editor to insert code tags is the one with the </> symbol.

eme1969

A link to the datasheet of the used sensor would help, a wiring diagram too and we might need the used source code (don't forget the code tags!).
google: [sensorname] datasheet

outsider

#5
Jan 14, 2019, 11:09 pm Last Edit: Jan 14, 2019, 11:14 pm by outsider
Code looks like that for a "TMP36", look closely at the flat side of the sensor with a magnifier, you may have to tilt it around to get the light right before you can see the markings.
With a 5 volt Arduino at room temp of 23°C, the ADC value for a TMP36 should be about 150.

jmetz

Attached is the TMP36 datasheet. And the following is the code that I used.

Code: [Select]
const int sensorPin = A0;
const float baselineTemp = 23.0;
void setup(){
  Serial.begin(9600); // open serial port
  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);
  //convert the ADC reading to voltage
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", Volts: ");
  Serial.print(voltage);
  Serial.print(", degrees C: ");
  // convert the voltage to temperature in degrees
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);
  if(temperature < baselineTemp){
    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(1);
}


The problem that I keep running into is when I set the baseline temp at 23, upload the code, and then put my finger on the sensor, all three LEDs turn on because the sensor is giving me numbers in the 60s. So I reset the baseline, upload the code, touch the sensor, and the readings are back in the 20s so no LEDs turn on.

Thank you all so much for your help!

pylon

Quote
Attached is the TMP36 datasheet. And the following is the code that I used.
Did you check that you're using a TMP36 sensor or did you just google that based on outsider's speculation?

If you're really using a TMP36 and an Arduino UNO with above code and you get 60°C if you touch the sensor, your sensor is broken and should be replaced. Be sure to never touch the sensor's pins as this would ruin the measurement.

Go Up