Go Down

Topic: Temperature Sensor (Read 581 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.

outsider

Or the sensor is loose in the breadboard and the code is doing close to 1000 updates per second.

jmetz

I checked the sensor. It is a TMP36. I will rewire the board and try again.

Svx

#10
Jan 17, 2019, 07:00 pm Last Edit: Jan 17, 2019, 07:02 pm by Svx
I have a similar issue. First of all, the baseline appears to be around 26.5, while the thermometer shows 24.4. I've observed that this termometer adds about 1 degree, so the actual room temperature should be around 23 degrees. The second issue is that when I put my fingers around the sensor, it jumps to 60-80, even the reading from tmp36 jumps to 200-250 and pretty much never comes back again until arduino is restarted.

EDIT: After moving 5v and ground wires to other pins on the breadboard the project now works as expected - except for the rather high baseline. Some issue with some of the first power pins on the breadboard.

pylon

Quote
After moving 5v and ground wires to other pins on the breadboard the project now works as expected - except for the rather high baseline.
The baseline is simply a lower temperature value where the LEDs are programmed to light up. As this value is chosen by you it's up on you to change it if you think it's wrong.

Quote
I have a similar issue. First of all, the baseline appears to be around 26.5, while the thermometer shows 24.4. I've observed that this termometer adds about 1 degree, so the actual room temperature should be around 23 degrees. The second issue is that when I put my fingers around the sensor, it jumps to 60-80, even the reading from tmp36 jumps to 200-250 and pretty much never comes back again until arduino is restarted.
Check the voltage of the 5V pin on your Arduino.

The sensor is providing 10mV per °C, so if your body temperature is 37°C it will have 0.87V on it's output. If your USB is only providing 4.7V your sketch will read the temperature as 43°C. If you use sensor with analog output, a constant and dependable supply voltage is key to get correct results.

Svx

How is an USB port not stable?

pylon

Quote
How is an USB port not stable?
Check your's with a multimeter. My computers have voltages from 4.6V to 5.3V on the USB ports.

MarkT

Most logic circuitry is happy for anything in the 4.5 to 5.5V range, sometimes 4.75 to 5.25V if its fussy.

Analog circuitry is not so casual!
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up