Circuit Creation

Temperature Sensor Project using Arduino

The temperature sensor project teaches you how to read analog and digital sensors to measure temperature. This is a fundamental skill for building weather stations, climate monitoring systems, and IoT projects.

Beginner

Components Required

Circuit Connections

The TMP36 is an analog temperature sensor that's easy to use and requires no special libraries. It provides a voltage output proportional to the temperature. Make sure the Arduino is not connected to USB while wiring.

TMP36 Sensor Pin Configuration:

The TMP36 has three pins when viewed from the flat side facing you:

  1. Left pin: VCC (Power Supply)
  2. Middle pin: VOUT (Output Voltage)
  3. Right pin: GND (Ground)

Wiring Steps:

  1. Connect the VCC pin (left) to 5V on Arduino.
  2. Connect the GND pin (right) to GND on Arduino.
  3. Connect the VOUT pin (middle) to analog pin A0 on Arduino.
Arduino temperature sensor circuit connection

Arduino Code

TMP36 Temperature Sensor Code:

                
/*
   Project: Arduino Temperature Sensor Project
   Description: This project demonstrates how to use a TMP36 temperature sensor with an Arduino to measure 

   Components:
     - Arduino Uno 
     - TMP36 Temperature Sensor 
     - Breadboard 
     - Jumper Wires 
     - USB Cable 
     - Optional: 16x2 LCD Display 
   Author: Circuit Creation RN

*/
//This code reads the temperature from the TMP36 sensor and prints it to the Serial Monitor in both Celsius and Fahrenheit.

// TMP36 Temperature Sensor
// Connect VOUT to A0
const int temperaturePin = A0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Read analog value from TMP36
  int analogValue = analogRead(temperaturePin);
  
  // Convert analog value to voltage
  // Arduino reads 0-1023 for 0-5V
  float voltage = analogValue * (5.0 / 1023.0);
  
  // TMP36 formula: (voltage - 0.5) * 100
  // Each degree is 10mV, and 0V = -50°C
  float temperatureC = (voltage - 0.5) * 100.0;
  
  // Convert to Fahrenheit (optional)
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  
  // Print to Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.print("°C / ");
  Serial.print(temperatureF);
  Serial.println("°F");
  
  delay(1000); // Wait 1 second before next reading
}
                
            

About the TMP36 Sensor

The TMP36 is a precision integrated circuit temperature sensor that requires no special libraries. It operates from -40°C to +125°C and outputs an analog voltage proportional to temperature.

Key Features:

Upload the Code

  1. Connect the Arduino board to your computer using the USB cable.
  2. Open the Arduino IDE and paste the code into a new sketch.
  3. Select the correct board and port from the Tools menu.
  4. Click the Upload button.
  5. Open the Serial Monitor (Ctrl + Shift + M) to see temperature readings.

Code Explanation

Let us understand how the Arduino code works step by step. This will help you modify the project later and build more projects.

Reading the Analog Value

analogRead(temperaturePin) reads the voltage from the TMP36 sensor. Arduino converts the analog voltage (0-5V) to a digital value (0-1023).

Converting Analog to Voltage

voltage = analogValue * (5.0 / 1023.0) converts the digital reading back to voltage. The 5V / 1023 ratio represents the resolution of the Arduino's analog-to-digital converter.

TMP36 Temperature Formula

The TMP36 outputs 10mV per degree Celsius, with 500mV at 0°C: temperatureC = (voltage - 0.5) * 100.0

This means:

Fahrenheit Conversion

To convert Celsius to Fahrenheit, we use: F = (C × 9/5) + 32

Serial Communication

Serial.begin(9600) initializes serial communication at 9600 baud rate. Serial.print() sends data to the Serial Monitor for viewing on your computer.

Common Mistakes & Troubleshooting

What You Learned