Temperature Sensor with Display: Measure and Show Room Temperature
What You’ll Learn
In this project, you’ll learn how to read data from a TMP36 temperature sensor and display the temperature on an LCD screen. This will help you understand how to interface with analog sensors and output data to a display, a common requirement in IoT and automation projects.
Components Needed
- 1 x Arduino Uno (or compatible board)
- 1 x TMP36 Temperature Sensor
- 1 x 16x2 LCD Display
- 1 x 10k ohm Potentiometer (for adjusting LCD contrast)
- Jumper wires
- Breadboard
The Concept
The TMP36 is an analog temperature sensor that provides a voltage output corresponding to the temperature. The sensor outputs a voltage of 500 mV at 0°C, and each 10 mV corresponds to a 1°C increase in temperature. We’ll use the Arduino to read the analog voltage, calculate the temperature, and display it on a 16x2 LCD in real-time.
Circuit Diagram
LCD Display:
- Connect the VSS pin of the LCD to GND.
- Connect the VDD pin to 5V.
- Connect the V0 pin (contrast control) to the middle pin of the potentiometer, and the other two pins to 5V and GND.
- Connect the RS pin to pin 12 of the Arduino.
- Connect the RW pin to GND.
- Connect the EN pin to pin 11 of the Arduino.
- Connect D4, D5, D6, and D7 pins of the LCD to pins 5, 4, 3, and 2 of the Arduino, respectively.
TMP36 Temperature Sensor:
- Connect the VCC pin of the TMP36 to 5V.
- Connect the GND pin to GND.
- Connect the Analog Out pin (middle pin) to the A0 analog input pin of the Arduino.
The Code for TMP36
#include <LiquidCrystal.h>
// Initialize the library with the LCD pin numbers
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int tempPin = A0; // Analog pin for TMP36
void setup() {
lcd.begin(16, 2); // Set up the LCD with 16 columns and 2 rows
lcd.print("Temp:"); // Print a label on the LCD
}
void loop() {
int analogValue = analogRead(tempPin); // Read the TMP36 sensor
float voltage = analogValue * (5.0 / 1023.0); // Convert the analog reading to voltage (0-5V)
float temperatureC = (voltage - 0.5) * 100; // Convert the voltage to Celsius
// Print the temperature to the LCD
lcd.setCursor(6, 0); // Move the cursor to the position to start printing
lcd.print(temperatureC);
lcd.print(" C");
delay(1000); // Update the temperature every second
}
How the Code Works for TMP36
Reading Analog Data:
The TMP36 outputs an analog voltage proportional to the temperature. TheanalogRead()function reads the sensor’s output from the analog pin (A0), returning a value between 0 and 1023, which corresponds to a voltage between 0 and 5V.Converting to Temperature:
The TMP36 sensor outputs 500 mV at 0°C, and the temperature increases by 1°C for every 10 mV. To convert the voltage to temperature in Celsius, we use the formula:float temperatureC = (voltage - 0.5) * 100;This adjusts for the 500 mV offset and scales the result to degrees Celsius.
Displaying on LCD:
The temperature is displayed on the 16x2 LCD screen. Thelcd.setCursor()function positions the cursor before printing the temperature. The display updates every second to show the current room temperature.
Customizing the Project
Fahrenheit Conversion: To display the temperature in Fahrenheit, you can modify the code as follows:
float temperatureF = (temperatureC * 9.0 / 5.0) + 32; lcd.print(temperatureF); lcd.print(" F");Temperature Logging: You can expand the project to log temperature data over time by storing readings in an array or sending the data to your computer via serial communication for further analysis.
Conclusion
In this project, you’ve learned how to read analog data from the TMP36 temperature sensor and display the temperature on a 16x2 LCD screen. You now understand how to handle analog sensor data, convert it into a meaningful temperature value, and output it to a display. This foundational knowledge can be applied to a wide range of sensor-based projects.

Comments
Post a Comment