0
\$\begingroup\$

I am using a TMP36 and an Arduino (like shown in the diagram below) to measure temperature.

The temperature sensor sensor is changing values abruptly. It looks like there is an error.

Can you please tell me if this is normal or not?

For the information I soldered additional wires to theTMP36 so that I can attach it somewhere next to a metal (but avoided short circuiting it.) I don't know if that changes anything in the reading.

enter image description here

The code looks like this:

int sensorPin = 0; 
void setup()
{
  Serial.begin(9600);  
  }
 
void loop()                  

{
 int reading = analogRead(sensorPin);  
 float voltage = reading * 5.0;
 float calculated = voltage /= 1024.0; 
 float temperature = (voltage - 0.5) * 100 ;

 
 Serial.print("voltage is "); Serial.println(voltage);  
 Serial.print("calculated is "); Serial.println(calculated);  
 Serial.print("temperature is "); Serial.print(temperature) ;Serial.println(" degrees C");
 Serial.println("");
 
 delay(1000);                                     
}

The result looks like this:

enter image description here

\$\endgroup\$
4
  • 1
    \$\begingroup\$ (1) Please (almost always) include a link in the question to the datasheet for the devices in question. (2) Your schematic shows no connection between the TMP36 pin 3 and the microcontroller board's GND. If there is one you should show a GND symbol connected to the board's GND pin. If there isn't then that may be your problem. \$\endgroup\$
    – Transistor
    Commented Jul 6, 2020 at 16:18
  • \$\begingroup\$ Thank you very much i did add the requirements and made my post more understandable... \$\endgroup\$ Commented Jul 6, 2020 at 16:56
  • 4
    \$\begingroup\$ There are a couple of problems with your schematic. (1) You have no current limiting resistor on the base of Q1. That may be affecting the microcontroller. (2) If Q1 ever turns on you will short-circuit your 12 V power supply. Fix those and try again. Notes on markdown: leave a blank line between your text and an image to avoid the odd word-wrap at the bottom of your post. Use the {} formatting button for code. (Make sure it's all indented properly.) \$\endgroup\$
    – Transistor
    Commented Jul 6, 2020 at 17:01
  • \$\begingroup\$ Add this command to the setup() function: pinMode(sensorPin, INPUT); \$\endgroup\$
    – tim
    Commented Jul 9, 2020 at 3:20

1 Answer 1

1
\$\begingroup\$

If the value jumps around, but returns to some baseline value, you may have Ground noise. Or VDD noise. Or cellphone energy upsetting the analog output. Add a large capacitor on the input to your Ardunio, with the ground end tied directly to Ardunio GND.

If some appliance, or the AirConditioner, shares the power wiring, then you likely have a cause.

\$\endgroup\$
2
  • \$\begingroup\$ I edited my post to fit well the actual reality . Thanks \$\endgroup\$ Commented Jul 6, 2020 at 16:57
  • \$\begingroup\$ what is the advantage of adding adding a big capacitance over a small one ? \$\endgroup\$ Commented Jul 11, 2020 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.