- Introduction
A temperature monitoring system is a setup designed to measure, monitor, and control the temperature and humidity in a specific environment.
- Objective
The aim of this experiment is to help the user:
- To learn how to use LM35 Sensor
- To interfacing LM35 sensor with microcontroller.
- To learn the applications of the circuit containing temperature sensors.
- Component knowledge
What is an LM35 Sensor? The LM35 is a precision temperature sensor that provides an output voltage linearly proportional to the temperature in Celsius. “It’s widely used in electronic projects for temperature measurement because it’s easy to interface with microcontrollers. Additionally, it provides accurate readings without the need for external calibration.
Figure: An LM 35 sensor
- Pin Identification of the LM35
“The LM35 comes in various packages; however, the most common one is the TO-92 package, which looks similar to a small transistor. Here’s how to identify its pins:
- Pin 1 (V+ / VCC): This is the power supply pin. Typically, you connect this pin to a 5V power source.
- Pin 2 (Vout / Signal): This is the output pin. The voltage here is directly proportional to the temperature, where 10 mV represents 1°C. For example, if the output is 250 mV, the temperature is 25°C.
- Pin 3 (GND): This is the ground pin, which should be connected to the ground of your circuit.
- Basic Connections:
- VCC (Pin 1): Connect to a 5V supply.
- Vout (Pin 2): Connect to an analog input pin of a microcontroller to read the voltage.
- GND (Pin 3): Connect to the ground of your circuit.
- How to LM35 sensor
Testing with a Multimeter
- Wiring the LM35:
- Pin 1 (VCC): Connect to a 5V power supply (you can use a battery or USB power from a PC).
- Pin 2 (Vout): Connect this pin to the positive (red) lead of your multimeter to measure voltage.
- Pin 3 (GND): Connect to the ground (negative terminal) of the power supply and the negative (black) lead of the multimeter.
- Power the Sensor: Once everything is connected, power the LM35 sensor with the 5V supply.
- Measure the Output Voltage:
- Set your multimeter to the DC voltage mode.
- The output voltage on Pin 2 (Vout) should now display a value.
- The LM35 gives 10 mV per degree Celsius. So, if you see 250 mV, that corresponds to 25°C (since 250 mV / 10 = 25°C).
- Verify Temperature: If you want to check if the sensor responds to temperature changes, try holding the sensor between your fingers to warm it up. The voltage output should increase as the temperature rises.
Example of Calculations:
If the multimeter shows 0.30V (300 mV), the temperature is: Temperature=300 mV/10=30∘C.
- Materials to be used
- Circuit diagram
Figure: Schematic diagram for LM35 sensor connection
NOTE: Refer to the Project 16 for LCD display connection.
Figure: Components used to make connection on the board
- Arduino Codes
#include <LiquidCrystal.h> // LCD library
#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 1024.0
#define PIN_LM35 A0 // pin connected to LM35 temperature sensor
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Pins for RS, E, D4, D5, D6, D7
void setup() {
Serial.begin(9600);
lcd.begin(16,2); // initialize the lcd (16 columns, 2 rows)
}
void loop() {
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in Celsius
float temperature_C = milliVolt / 10;
float temperature_F = temperature_C * 9 / 5 + 32; // convert Celsius to Fahrenheit
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print(temperature_C); // print the temperature in Celsius
lcd.print("°C");
lcd.setCursor(0, 1); // start to print at the second row
lcd.print(temperature_F); // print the temperature in Fahrenheit
lcd.print("°F");
// print the temperature to Serial Monitor
Serial.print(temperature_C);
Serial.print("°C ~ ");
Serial.print(temperature_F);
Serial.println("°F");
delay(500);
}
- Code knowledge
This Arduino code reads the temperature from an LM35 sensor, displays it on an LCD screen, and outputs the reading to the Serial Monitor. Let’s go through it step-by-step to make it easy to understand.
#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 1024.0
- ADC_VREF_mV and ADC_RESOLUTION: These constants represent the reference voltage (5000 mV for 5V Arduino) and the ADC resolution (1024 for Arduino’s 10-bit ADC).
This is where the code reads and processes the temperature data and displays it.
int adcVal = analogRead(PIN_LM35);
- analogRead(PIN_LM35): Reads the analog input from the LM35 sensor and stores it in the variable adcVal. The LM35 sensor outputs a voltage proportional to the temperature: 10mV per degree Celsius.
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
This line calculates the sensor output voltage in millivolts. It multiplies adcVal by the reference voltage divided by the ADC resolution (5000 mV / 1024).
The result (milliVolt) represents the actual voltage read from the sensor.
float temperature_C = milliVolt / 10;
This line converts the voltage to temperature in Celsius. The LM35 outputs 10mV per °C, so dividing the voltage by 10 gives the temperature in Celsius.
float temperature_F = temperature_C * 9 / 5 + 32; // convert Celsius to Fahrenheitfloat temperature_C = milliVolt / 10;
This converts the Celsius temperature to Fahrenheit using the standard conversion formula.
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print(temperature_C); // print the temperature in Celsius
lcd.print("°C");
lcd.clear();: Clears any previous display on the LCD.
lcd.setCursor(0, 0);: Sets the cursor to the first row and first column.
lcd.print(temperature_C); and lcd.print(“°C”);: Display the temperature in Celsius on the first row.
lcd.setCursor(0, 1); // start to print at the second row
lcd.print(temperature_F); // print the temperature in Fahrenheit
lcd.print("°F");
- lcd.setCursor(0, 1);: Sets the cursor to the second row, first column.
- lcd.print(temperature_F); and lcd.print(“°F”);: Display the temperature in Fahrenheit on the second row.
Step 7: Print Temperature to Serial Monitor:
// print the temperature to Serial Monitor
Serial.print(temperature_C);
Serial.print("°C ~ ");
Serial.print(temperature_F);
Serial.println("°F");
First, this section sends the temperature values to the Serial Monitor. Then, it displays both Celsius and Fahrenheit values so you can easily monitor the temperature.
- Results
This project uses LM35 temperature sensor to measure temperature, displays the temperature in Celsius and Fahrenheit on an LCD, and prints the same values to the Serial Monitor.
Expected Outputs:
1. Serial Monitor Output
Every 500 milliseconds, the temperature in Celsius and Fahrenheit is printed.
For example: 25.00°C ~ 77.00°F
The values will vary based on the current temperature measured by the LM35 sensor.
2. LCD Output (Visible Output)
The LCD displays two lines:
First line: Temperature in Celsius
Second line: Temperature in Fahrenheit
For example:
25.00°C
77.00°F
……………………………………………………………………………………………………………………