I have made a custom board out of Arduino Nano with ATmega328 (not 328p) and using a temperature sensor TMP36 (TMP36GRTZ-REEL7). Whenever I run the code, it gives me -50 Celsius and -58 Fahrenheit all the time without changing. The values are frozen on these two numbers all the time no matter of the temperature. I changed the code twice and still get the same value so I think the code is fine and there's something wrong with my hardware. Fortunately, I have 2 versions of this temperature on my board, one is a SMD and the other is a through hole. The through hole is also showing the same result. I turned it off by cutting the power line on either sensors and it's still reading -50 degrees.
Can you guys help me out please? I'll attach a schematic of my design.
Double check that data connections on your board between the sensor and the arduino and make sure there making a solid connection, otherwise it could be a problem with your code.
I double checked the connections pin by pin and it looks good. I thought maybe connecting it to ADC7 (only ADC function pin) could be the problem? because on the original Arduino boards they connect the Vout from sensor to A0 ~ A5 which are PC1 ~ PC5 multifunction pins.
Actually, no, I didn't prototype it myself, I watched the videos of people doing it and it worked for them, I used their arrangements and their code.
I was using the micro's internal temperature reader and the accuracy was very poor that's why I decided to use this sensor.
Also, The through hole TMP36 started printing 67.19 degrees after I found a mistake in my pin number declarations and fixed it. But the problem is the temperature here is 24 degrees right now.
And it changes when I tough the sensor and goes up to 74 degrees. So, I think the same problem should be possible with the SMD, the pins are not declared correctly. Let me double check and get back to you with my sketch.
Alright guys, I have the through hole TMP36 working. But when I set the voltage to 3.3v, it's off by +3 degrees C.
My actual design will need to work with 3 volts and when I set the voltage to 3 volts, the temperature output is unstable (it keeps jumping +7 degrees) and the output value itself shows -10C below what the room temperature is.
Here's the sketch:
#include <TMP36.h>
#define SENSOR_PIN 16 //Start sensor
#define SENSOR_PORT() pinMode(SENSOR_PIN,OUTPUT)
#define SENSOR_HIGH() digitalWrite(SENSOR_PIN,HIGH)
#define SENSOR_LOW() digitalWrite(SENSOR_PIN,LOW)
//Create an instance of the TMP36 class and
//define the pin the sensor is connected to
//If using 3.3v Arduino, change 5 to 3.3
TMP36 myTMP36(20, 3.0); //(pin#, voltage)
void setup() {
serial.begin (9600);
}
void loop() {
SENSOR_HIGH();
//create a variable and store the current temperature in
//celsius in it using the getTempC function
float celsius = myTMP36.getTempC();
//create a variable and store the current temperature in
//fahrenheit in it using the getTempF function
float fahrenheit = myTMP36.getTempF();
//Print the data to the Serial monitor
Serial.print("Celsius: ");
Serial.print(celsius);
Serial.print(" Fahrenheit: ");
Serial.println(fahrenheit);
delay(150); // Delay added for easier readings
}