Arduino LM35 Temperature Experiment

Arduino LM35 Temperature Measurement Experiment

Introduction

In this experiment, you’ll learn how to measure temperature using the LM35 temperature sensor and an Arduino. The LM35 outputs a voltage directly proportional to the temperature in Celsius, making it easy to use with an Arduino's analog input.

Components Needed

Circuit Setup

  1. Place the LM35 sensor on the Arduino breadboard shield. It has three pins: VCC, Output, and GND (from left to right, facing the flat side).
  2. Connect the VCC pin of the LM35 to the 5V pin on the Arduino R4 Minima.
  3. Connect the GND pin of the LM35 to the GND pin on the Arduino.
  4. Connect the Output pin of the LM35 to the Arduino's analog input pin A0 using jumper cables.

Code for Temperature Measurement

Upload the following code to your Arduino to measure and display the temperature in Celsius on the Serial Monitor:


// LM35 temperature sensor connected to analog pin A0
const int sensorPin = A0;

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

void loop() {
    // Read the analog input from the LM35 sensor
    int sensorValue = analogRead(sensorPin);
    
    // Convert the analog value to voltage (0 - 5V)
    float voltage = sensorValue * (5.0 / 1023.0);
    
    // Convert voltage to temperature in Celsius
    float temperatureC = voltage * 100.0;
    
    // Print temperature to Serial Monitor
    Serial.print("Temperature: ");
    Serial.print(temperatureC);
    Serial.println(" °C");
    
    delay(1000); // Wait 1 second between readings
}
            

Explanation

The LM35 outputs 10mV per degree Celsius. By reading the analog value and converting it to a voltage, we can calculate the temperature as follows:

This code displays the temperature on the Serial Monitor in Celsius.

Troubleshooting