Arduino Digital Thermometer with LM35

Difficulty Level: Beginner

In this experiment, you'll build a simple digital thermometer using the LM35 temperature sensor and an Arduino. The temperature will be displayed in degrees Celsius on the serial monitor.

Needed Components with eBay Links

Understanding the LM35 Sensor

The LM35 is a linear temperature sensor, meaning its output voltage is directly proportional to the temperature in degrees Celsius. The output increases by 10 mV for every degree Celsius rise in temperature. For example, at 25°C, the output voltage is 250 mV.

Key Functions

Wiring the Circuit

Connect the LM35 sensor to your Arduino as follows:

Arduino Code

Here’s the code to read the temperature:


// Digital Thermometer with LM35

int sensorPin = A0;  // Analog pin connected to LM35
float temperature;   // Variable to store the temperature value

void setup() {
  Serial.begin(9600);  // Initialize serial communication
  Serial.println("Digital Thermometer with LM35");
}

void loop() {
  int sensorValue = analogRead(sensorPin);  // Read the analog input
  temperature = (sensorValue * 5.0 * 100.0) / 1024.0;  // Convert the value to temperature in Celsius

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  delay(1000);  // Wait for 1 second before reading again
}
            

Upload & Test

  1. Connect your Arduino to your computer using a USB cable.
  2. Open the Arduino IDE and copy the code above into the editor.
  3. Select your board and the correct port in the IDE.
  4. Upload the code by clicking the upload button.
  5. Open the Serial Monitor (Tools > Serial Monitor) and set the baud rate to 9600. You will see the temperature readings in degrees Celsius displayed every second.

Code Breakdown

The LM35 outputs a voltage proportional to the temperature. The Arduino reads this voltage using analogRead(). The conversion formula translates the analog reading into a temperature value by multiplying the sensor value by 5 (for the 5V reference), 100 (due to the 10 mV/°C conversion factor), and dividing by 1024 (since the Arduino's ADC provides a 10-bit reading).

Conclusion

This simple digital thermometer demonstrates how to read and display analog data from a sensor. By expanding on this, you can build more complex temperature monitoring projects, such as a thermostat or data logger.