Simple Thermometer Using TMP36 and ESP32

Introduction: Simple Thermometer Using TMP36 and ESP32

The TMP36 temperature IC is a very cheap IC that can be used as a digital thermometer for all kinds of applications from measuring the temperature of your room to measuring the inner temperature your meat, and it costs under $2! This project uses the TMP36 IC as a simple, accurate, easy-to-build and cheap thermometer, that you can make in less than 5 minutes for only $7!!!

Using the TMP36 temperature IC with an ESP32 is subtly different than an Arduino, because but the formula in the datasheet does not apply to the ESP32, due to the way the ESP32 processes the digital signal. This difference is noted under the code, and how the code changes as a result of the ESP32's quirk!

Step 1: Tools and Materials

  • ESP32 Development board - $5
  • TMP36 Temperature Sensor - $1.5
  • 3 pieces of jumper wires - a few cents
  • [OPTIONAL] Breadboard

Step 2: Circuitry

  1. Connect the middle pin of the temperature IC, TMP36, to pin D6 on the ESP32 Development Board.
  2. Connect the left pin with the flat edge of the temperature IC facing towards you, to the 3.3V pin on the ESP32 development board
  3. Lastly, connect the right pin of the temperature IC to the GND pin on the ESP32 development board.

Step 3: Coding

There are very subtle differences in when coding a temperature sensor on the ESP32 board as opposed to the Arduino. For the ESP32 board, we do not need to multiply the raw sensor reading by the voltage, but simply needs to be normalized by the 2^10 bits.

const int tempPin = 2;     //analog input pin constant<br>
int tempVal;    // temperature sensor raw readings
float volts;    // variable for storing voltage 
float temp;     // actual temperature variable
void setup()
{
  // start the serial port at 9600 baud
  Serial.begin(9600);
}
void loop()
{
 //read the temp sensor and store it in tempVal
 tempVal = analogRead(tempPin);
 volts = tempVal/1023.0;             // normalize by the maximum temperature raw reading range
 temp = (volts - 0.5) * 100 ;         //calculate temperature celsius from voltage as per the equation found on the sensor spec sheet.
Serial.print(" Temperature is:   "); // print out the following string to the serial monitor
Serial.print(temp);                  // in the same line print the temperature
Serial.println (" degrees C");       // still in the same line print degrees C, then go to next line.
delay(1000);                         // wait for 1 second or 1000 milliseconds before taking the next reading. 
}

Step 4: Demonstration Video

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

Be the First to Share

    Recommendations

    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020

    2 Discussions

    0
    AbdieT
    AbdieT

    Question 5 months ago on Introduction

    Mr. TeckMartain,

    Why are you using 1/1023 instead of 1/4095? Isn't ESP32 a 12 bit system? Please clarify. Also, please give a bit more detail on why your measured value is only divided by 1023 but not multiplied by 3.3 volts. Have you confirmed this with the ESP32 manufacturer? Thanks.

    Abdie

    0
    frucot
    frucot

    12 months ago

    For me, normalization of 2^12 seems not to work : for a temp of approximately 25°C it give me -30°C instead of +25°C.
    A piece of code :
    tempVal =analogRead(tempPin);
    volts = tempVal / (4095.0); // normalize by the maximum temperature raw reading range
    temp = (volts -0.5) *100; //calculate temperature celsius from voltage as per the equation found on the sensor spec sheet.

    Why ?