0
0
AutocadHow-ToBeginner · 4 min read

Arduino Project for Digital Thermometer: Simple Guide & Code

To create a digital thermometer with Arduino, connect a temperature sensor like LM35 to an analog pin and read its voltage. Use analogRead() to get sensor data, convert it to temperature, and display it on the Serial Monitor or an LCD screen.
📐

Syntax

This is the basic syntax to read temperature from an LM35 sensor connected to an Arduino analog pin:

  • analogRead(pin): Reads the voltage value from the sensor (0-1023).
  • Convert the analog value to voltage: voltage = analogValue * (5.0 / 1023.0).
  • Convert voltage to temperature in Celsius: temperatureC = voltage * 100 (because LM35 outputs 10mV per °C).
arduino
int sensorPin = A0;  // Analog pin where LM35 is connected
int sensorValue = 0;  // Variable to store sensor reading
float voltage = 0.0;  // Voltage from sensor
float temperatureC = 0.0;  // Temperature in Celsius

void setup() {
  Serial.begin(9600);  // Start serial communication
}

void loop() {
  sensorValue = analogRead(sensorPin);  // Read analog value
  voltage = sensorValue * (5.0 / 1023.0);  // Convert to voltage
  temperatureC = voltage * 100;  // Convert voltage to temperature
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");
  delay(1000);  // Wait 1 second before next reading
}
💻

Example

This example reads temperature from an LM35 sensor connected to analog pin A0 and prints the temperature in Celsius to the Serial Monitor every second.

arduino
int sensorPin = A0;

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

void loop() {
  int sensorValue = analogRead(sensorPin);
  float voltage = sensorValue * (5.0 / 1023.0);
  float temperatureC = voltage * 100;
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");
  delay(1000);
}
Output
Temperature: 23.45 °C Temperature: 23.50 °C Temperature: 23.48 °C ... (updates every second)
⚠️

Common Pitfalls

Common mistakes when building a digital thermometer with Arduino include:

  • Not connecting the sensor correctly (wrong pins or loose wires).
  • Using the wrong analog reference voltage, which affects temperature accuracy.
  • Forgetting to convert the analog reading to voltage before calculating temperature.
  • Not adding a delay in the loop, causing too fast readings and cluttered output.

Always double-check wiring and use the correct formulas for your sensor.

arduino
/* Wrong way: Missing voltage conversion and wrong print */
int sensorPin = A0;

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

void loop() {
  int sensorValue = analogRead(sensorPin);
  // Incorrect: printing raw sensor value instead of temperature
  Serial.print("Raw sensor value: ");
  Serial.println(sensorValue);
  delay(1000);
}

/* Correct way: Convert to voltage and temperature */

void loop() {
  int sensorValue = analogRead(sensorPin);
  float voltage = sensorValue * (5.0 / 1023.0);
  float temperatureC = voltage * 100;
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");
  delay(1000);
}
📊

Quick Reference

Tips for your Arduino digital thermometer project:

  • Use analogRead() to get sensor data.
  • Convert analog value to voltage: voltage = analogValue * (5.0 / 1023.0).
  • Convert voltage to temperature for LM35: temperatureC = voltage * 100.
  • Use Serial.begin(9600) and Serial.print() to display results.
  • Add delay(1000) to read every second.

Key Takeaways

Connect the LM35 sensor to an analog pin and use analogRead() to get data.
Convert the analog reading to voltage before calculating temperature.
Use Serial Monitor to display temperature readings clearly.
Add delays to avoid flooding the output with too many readings.
Check wiring carefully to avoid sensor reading errors.