Go Down

Topic: TMP36 unusual readings (Read 70 times) previous topic - next topic

DNABlast

So I am doing the Arduino sketch involving the "love meter" and decided that having a set baseline is silly if you find yourself in a hotter (or colder) environment that you set up in. I decided to program the sensor to set its baseline up for 5 seconds at the beginning before doing the readout. The programing seemed to work, but my sensor goes off the rails when I pinch it to increase the temp showing temps as high as 60 C (140 F) and it won't decrease past 40 C (104 F) any thoughts on this? I'll include my code below for all who are interested.

const int sensorPin = A0;
float baselineTemp = 0.0;
float currentset = 0.0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  for(int pinNumber = 2; pinNumber <5; pinNumber++){
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
  while(millis() < 5000) {
    // currentset is being turned into sensor value
    currentset = analogRead(sensorPin);
    // currentset is being turned into voltage
    currentset = (currentset/1024.0) * 5.0;
    // currentset is being turned into temp in C
    currentset = (currentset - .5) * 100;
    if( currentset > baselineTemp) {
      baselineTemp = currentset;
    }
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  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.print(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(1000);
    digitalWrite(4, LOW);
    delay(250);
   }
   delay(100);
}

DaveEvans

What have you done to try to figure out the reason for the problem (such as other tests, internet research, etc)?

Wawa

#2
Sep 25, 2016, 01:54 am Last Edit: Sep 25, 2016, 02:11 am by Wawa
Usually a wiring problem.
The TMP36 works better if ground is directly connected to a ground pin of the Arduino.
Not via a breadboard with other devices/LEDs that use the same ground.
3.3volt supply might also be cleaner than a 5volt supply.

Use this sketch for testing.
Leo..
Code: [Select]
// TMP36 temp

void setup() {
  analogReference(INTERNAL); // use 1.1volt bandgap Aref
  Serial.begin(9600);
}

void loop() {
  Serial.println((analogRead(A0) * 0.1039) - 50.0, 1);
  delay(1000);
}


Edit:
Your code prints everything on one line.
Use Serial.println, so the next item will be printed on the next line.

 

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy