Other Useful Links From Around The Web:
Benne is professional Systems Engineer with a deep expertise in Arduino and a passion for DIY projects.
If you are looking for an inexpensive, accurate, easy-to-use temperature sensor, then LM35 is an excellent choice. It has an accuracy of ±¼°C at room temperature and ±¾°C over a full −55°C to 150°C temperature range. It does not require any external trimming, although the main drawback of this sensor is that it outputs data in analog format, making it very prone to external noise and interference. So, in this tutorial, we will learn how to wire up a LM35 Temperature Sensor with Arduino and also we will output the temperature data in the serial monitor window.
LM35 Temperature Sensor Pinout
VCC is the power supply pin of the LM35 temperature sensor IC that can be connected to 4V or 32V of the supply.
GND is the ground pin of the LM35 temperature sensor IC and it should be connected to the supply ground.
OUT This is the temperature sensor analog output pin. This is the analog output pin of the temperature sensor, the output voltage on this pin is directly proportional to the temperature.
LM35 Temperature Sensor
The LM35 is a low-power, low-cost, high-precision temperature sensor designed and manufactured by Texas instruments. This IC provides a voltage output that is linearly proportional to the change in temperature.
The LM35 sensor is moderately precise and its robust construction makes it suitable for various environmental conditions. Additionally, you don’t need any external component to calibrate this circuit and it has a typical accuracy of ±0.5°C at room temperature and ±1°C over a full −55°C to +155°C temperature range. It has an operating voltage of 4V to 30V and consumes 60-uA current while it’s in working state, this also makes it perfect for battery-powered applications.
There are two disadvantages of this sensor. The first big disadvantage of this sensor is that it cannot measure negative temperature, for that you have to bias it with a dual polarity supply. If your project requires negative temperature measurements, you can opt for a LM36 sensor. The second disadvantage of this sensor is that it’s very sensitive to noise because it outputs data in analog format. If you want to learn more about this sensor you can check out the Datasheet of LM35 Temperature Sensor IC.
How the LM35 Temperature Sensor Measures Temperature:
The LM35 temperature sensor uses the basic principle of a diode to measure known temperature value. As we all know from semiconductor physics, as the temperature increases the voltage across a diode increases at a known rate. By accurately amplifying the voltage change, we can easily generate a voltage signal that is directly proportional to the surrounding temperature. The screenshot below shows the internal schematic of LM35 temperature sensor IC according to the datasheet.
In practice, this diode that they are using to measure the temperature is not actually a PN Junction diode but its a diode-connected transistor. That is why the relationship between the forward voltage and the transistor is so linear. The temperature coefficient vs collector current graph below gives you a better understanding of the process.
If you want to learn more about the topic, you can check out the documentation on Diode-Based Temperature Measurement Techniques by Texas Instruments.
How does the LM35 Temperature Sensor Works in our Circuit
The working of the LM35 Temperature Sensor is very simple and easy to understand. We just have to connect 5V and Ground to the sensor and we need to measure the output voltage from the output pin.
According to the datasheet of the device, the sensor should give us 10mv/°C. So, if the temperature of the room is 18°C then the sensor should give us 180mV at the output pin and the animation above shows exactly that. If you connect a multimeter to the output pin of the sensor and measure the output voltage you will get something similar. If you are getting wired voltage output from the sensor then we would recommend you to go through our previous article on LM35 Temperature Sensor Not Working? where we have encountered some weird issues that we couldn’t find any solution to.
Commonly Asked Questions about the LM35 Temperature Sensor IC
What is the LM35 temperature sensor used for?
Like any other temperature sensor, it can be used for many different applications, mainly you can use it to measure body temperature of an object, and also it can measure ambient temperature.
Is LM35 a thermistor?
Thermistors have some benefits over other kinds of temperature sensors such as analog output chips (LM35/TMP36 ) or digital temperature sensor chips (DS18B20) or thermocouples.
What are the advantages and disadvantages of thermistors over LM35?
The main advantages of the thermistor are large temperature coefficient of resistance, high sensitivity, small heat capacity, fast response; but the main disadvantages are poor interchangeability and non-linearity of thermoelectric characteristics which is to expand the measurement.
What is the minimum typical temperature that the LM35 can pick up?
As the LM35 device draws only 60 µA from the supply, it has very low self-heating of less than 0.1°C in still air. The LM35 device is rated to operate over a −55°C to 150°C temperature range, while the LM35C device is rated for a −40°C to 110°C range (−10° with improved accuracy).
Arduino LM35 Temperature Sensor Circuit Diagram
Now that we have understood how the LM35 Temperature Sensor works we can connect all the required wires to Arduino UNO. The arduino lm35 connection diagram is shown below-
Connecting the LM35 sensor to the Arduino is really simple. You just need to connect 5V power to the sensor and you need to connect the output of the sensor to the A0 pin of the Arduino. Once the connection is done you need to write the code to convert the output voltage of the sensor to temperature data. For that, first, you need to convert the ADC values to voltage and multiply that voltage to 10 and you will get the output in temperature. With that, you’re now ready to upload the code to Arduino. An image showing the actual Arduino LM35 hardware setup is shown below.
Arduino LM35 Temperature Sensor Code
The Arduino Code for Interfacing the LM35 Temperature Sensor is very simple and easy to understand. We just need to read the analog data out of the sensor and convert it to temperature data.
We Initialize our code by defining the pin in which the LM35 Temperature sensor is connected.
#define sensor_pin A0 // LM35 is connected to this PIN
Next, we have our setup() function, in the setup, we just need to initialize the serial monitor for debugging.
void setup() { // Init serial at 9600 baud Serial.begin(9600); }
Next we have our loop function, in the loop function we read the pin and store the ADC data in adcData variable. Next, we convert the ADC data to the voltage value and store it in a local variable named voltage, and finally, we convert the voltage value to temperature and store it in a variable named temperature and print that in the serial monitor window. At last, we added 800ms and finished the code.
void loop() { //Read Raw ADC Data int adcData = analogRead(sensorPin); // Convert that ADC Data into voltage float voltage = adcData * (5.0 / 1024.0); // Convert the voltage into temperature float temperature = voltage * 100; // Print the temperature data Serial.print(“Temperature: “); Serial.print(temperature); Serial.println(“*C”); delay(800); // wait a second between readings }
Working of the Arduino LM35 Sensor Based Temperature Measurement
The gif below shows the Arduino LM35 Temperature Sensor in action. On the left-hand side, we have placed the Arduino with the temperature sensor connected to A0 pin of the Arduino and on the right-hand side, we have our serial monitor window. When we warm up the temperature sensor with the hot air station, you can see the temperature value rises on the serial monitor window.
Projects using the LM35 Temperature Sensor
Previously we have used this LM35 Temperature sensor to build many interesting projects. If you want to know more about those topics, links are given below.
If you are a beginner in electronics and you want to learn more about 8051 Microcontroller, and ADC then this project is for you. In this project, we have interfaced the popular LM35 Temperature with 8051 to make our own Thermometer and displayed the data on a 16X2 LCD Display.
If you are new to IoT space and searching for basic projects with IoT, this project could be for you because in this project we have used a LM35 temperature sensor with the very popular ESP8266 Microcontroller to send and plot data to a thingspeak server.
If you want to learn more about the PIC microcontroller and its working, this project can be a good starting point for you, because in this project we have used the ADC of the PIC microcontroller to interface a LM35 Temperature sensor and printed the temperature data to an LCD.
If you are looking for a simple, easy to build,temperature controlled switch then this project can be a good start for you because in this project we have used the populer LM35 Temperature sensor to do just that.
Supporting Files
// LM35 is connected to this PIN#define sensorPin A0void setup() {// Init serial at 9600 baudSerial.begin(9600);}void loop() {//Read Raw ADC Dataint adcData = analogRead(sensorPin);// Convert that ADC Data into voltagefloat voltage = adcData * (5.0 / 1024.0);// Convert the voltage into temperaturefloat temperature = voltage * 100;// Print the temperature dataSerial.print(“Temperature: “);Serial.print(temperature);Serial.println(“*C”);delay(800); // wait a second between readings}
LM35 with I2C LCD and Arduino example code
If you want to make a standalone thermometer that doesn’t need a computer, it can be nice to know how to display the temperature readings on an LCD display.
With the example code below, you can display the temperature readings on a 16×2 character I2C LCD.
Connecting the I2C LCD is fairly easy as you can see in the wiring diagram below. You can check out my detailed tutorial on How to control a character I2C LCD with Arduino for more information. If you want to use a standard non-I2C LCD instead, take a look at How to use a 16×2 character LCD with Arduino.
The connections are also given in the table below:
I2C LCD Connections
I2C Character LCD | Arduino |
GND | GND |
VCC | 5 V |
SDA | A4 |
SCL | A5 |
Note that the LM35 temperature sensor is connected in the same way as before.
Installing the required Arduino libraries
To use an I2C LCD, you need to install the LiquidCrystal_I2C Arduino library.
To install this library, go to Tools > Manage Libraries (Ctrl + Shift + I on Windows) in the Arduino IDE. The Library Manager will open and update the list of installed libraries.
Now search for ‘liquidcrystal_i2c’ and look for the library by Frank de Brabander. Select the latest version and then click Install.
LM35 with I2C LCD example code
/* LM35 analog temperature sensor with I2C LCD and Arduino example code. More info: https://www.makerguides.com */ // Include the required Arduino libraries: #include “LiquidCrystal_I2C.h” // Create a new instance of the LiquidCrystal_I2C class: LiquidCrystal_I2C lcd(0x27, 16, 2); // Degree symbol: byte Degree[] = { B00111, B00101, B00111, B00000, B00000, B00000, B00000, B00000 }; // Define to which pin of the Arduino the output of the LM35 is connected: #define sensorPin A0 void setup() { // Start the LCD and turn on the backlight: lcd.init(); lcd.backlight(); // Create a custom character: lcd.createChar(0, Degree); } void loop() { // Get a reading from the temperature sensor: int reading = analogRead(sensorPin); // Convert the reading into voltage: float voltage = reading * (5000 / 1024.0); // Convert the voltage into the temperature in degree Celsius: float temperature = voltage / 10; // Print the temperature on the LCD; lcd.setCursor(0, 0); lcd.print(“Temperature:”); lcd.setCursor(0, 1); lcd.print(temperature); lcd.write(0); // print the custom character lcd.print(“C”); delay(1000); // wait a second between readings }
You should see the following output on the LCD:
LM35 Temperature Sensor
The LM35 is a low voltage, precision centigrade temperature sensor manufactured by Texas Instruments. It is a chip that provides a voltage output that is linearly proportional to the temperature in °C and is, therefore, very easy to use with an Arduino.
The LM35 temperature sensor is fairly precise, never wears out, works under many environmental conditions and requires no external components to work. In addition, the LM35 sensor does not require calibration and provides a typical accuracy of ±0.5°C at room temperature and ±1°C over a full −55°C to +155°C temperature range.
The sensor can be powered with a 4V to 30V power supply and consumes less than 60µA during active temperature conversions, providing very low self-heating (less than 0.08°C in still air).
Here are the complete specifications:
Power supply | 4V to 30V |
Current draw | 60µA |
Temperature range | −55°C to +155°C |
Accuracy | ±0.5°C |
Output scale factor | 10mV/°C |
Output at 25°C | 250mV |
For more information, please refer below datasheet.
The only disadvantage of the LM35 sensor is that it requires a negative bias voltage to measure negative temperature. So if you are planning to use the sensor to measure negative temperature, it is recommended that you use TMP36 temperature sensor. The TMP36 by Analog Devices is fairly accurate (-40°C to 125°C) and has the advantage of being able to measure negative temperatures without the need for negative bias voltage. You can find a dedicated tutorial for the TMP36 below.
A better alternative to the LM35 is to use a digital temperature sensor like the DS18B20 which comes in the same package. Digital temperature sensors have better noise immunity which is useful when the sensor is placed at a distance or in an electrically noisy environment.
LM35 analog temperature sensor with Arduino example code
With the following example code, you can read the temperature from an LM35 sensor and display it in the Serial Monitor.
You can upload the example code to your Arduino using the Arduino IDE.
/* LM35 analog temperature sensor with Arduino example code. More info: https://www.makerguides.com */ // Define to which pin of the Arduino the output of the LM35 is connected: #define sensorPin A0 void setup() { // Begin serial communication at a baud rate of 9600: Serial.begin(9600); } void loop() { // Get a reading from the temperature sensor: int reading = analogRead(sensorPin); // Convert the reading into voltage: float voltage = reading * (5000 / 1024.0); // Convert the voltage into the temperature in degree Celsius: float temperature = voltage / 10; // Print the temperature in the Serial Monitor: Serial.print(temperature); Serial.print(” \xC2\xB0″); // shows degree symbol Serial.println(“C”); delay(1000); // wait a second between readings }
You should see the following output in the Serial Monitor:
Make sure that the baud rate of the Serial Monitor is also set to 9600.
How the code works
First, I defined to which pin of the Arduino the VOUT pin of the sensor is connected. In this case, we used the analog pin A0. The statement #define can be used to give a name to a constant value. The compiler will replace all references to this constant with the defined value when the program is compiled. So everywhere you mention
sensorPin
, the compiler will replace it with A0 when the program is compiled.
// Define to which pin of the Arduino the output of the LM35 is connected: #define sensorPin A0
In the setup section of the code, we begin serial communication at a baud rate of 9600.
void setup() { // Begin serial communication at a baud rate of 9600: Serial.begin(9600); }
In the loop section of the code, we start by taking a reading from the sensor with the function
analogRead(pin)
.
// Get a reading from the temperature sensor: int reading = analogRead(sensorPin);
Next, we use the formulas that I mentioned earlier in the article to convert the reading into voltage and then into temperature.
// Convert the reading into voltage: float voltage = reading * (5000 / 1024.0); // Convert the voltage into the temperature in degree Celsius: float temperature = voltage / 10;
Lastly, the results are printed in the Serial Monitor:
// Print the temperature in the Serial Monitor: Serial.print(temperature); Serial.print(” \xC2\xB0″); // shows degree symbol Serial.println(“C”);
Arduino Code – Simple Thermometer
The following sketch shows a quick way to read LM35 temperature sensor and can serve as the basis for more practical experiments and projects. It simply reads the value from the LM35 using analog port A0 and prints the current temperature (in both °C and °F) on the serial monitor. Go ahead and upload it to your Arduino.
// Define the analog pin, the LM35's Vout pin is connected to #define sensorPin A0 void setup() { // Begin serial communication at 9600 baud rate Serial.begin(9600); } void loop() { // Get the voltage reading from the LM35 int reading = analogRead(sensorPin); // Convert that reading into voltage float voltage = reading * (5.0 / 1024.0); // Convert the voltage into the temperature in Celsius float temperatureC = voltage * 100; // Print the temperature in Celsius Serial.print("Temperature: "); Serial.print(temperatureC); Serial.print("\xC2\xB0"); // shows degree symbol Serial.print("C | "); // Print the temperature in Fahrenheit float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; Serial.print(temperatureF); Serial.print("\xC2\xB0"); // shows degree symbol Serial.println("F"); delay(1000); // wait a second between readings }
You should see the following output in the serial monitor.
Code Explanation:
The sketch starts by defining the Arduino pin to which the sensor’s Vout pin is connected.
#define sensorPin A0
In the setup, we initialize the serial connection with the computer.
void setup() { Serial.begin(9600); }
In the loop, we first read in the analog signal from the LM35 using the
analogRead()
function.
int reading = analogRead(sensorPin);
Next, we will use the formulas we discussed earlier in the article to convert the analog reading into voltage and then into temperature.
float voltage = reading * (5.0 / 1024.0); float temperatureC = voltage * 100;
Next, the results are printed on the Serial Monitor.
Serial.print("Temperature: "); Serial.print(temperatureC); Serial.print("\xC2\xB0"); // shows degree symbol Serial.print("C | ");
The temperature value we get is in Celsius (°C). It is converted in to Fahrenheit (°F) using a simple formula and printed on the Serial Monitor.
T(°F) = T(°C) × 9/5 + 32
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; Serial.print(temperatureF); Serial.print("\xC2\xB0"); // shows degree symbol Serial.println("F");
Improve the precision of the readings
Because we used the default reference voltage of the Arduino for analog input (i.e. the value used as the top of the input range), the maximum resolution we get from the ADC is 5000/1024 = 4.88 mV or 0.49°C.
If we want a higher precision, we can use the built-in 1.1 V reference from the Arduino instead. This reference voltage can be changed using the function analogReference().
With 1.1 V as the reference voltage, we get a resolution of 1100/1024 = 1.07 mV or 0.11°C. Note that this limits the temperature range that we can measure to 0 to 110 degrees Celsius.
I have highlighted the lines you need to add/change in the code below:
/* LM35 analog temperature sensor with Arduino example code. More info: https://www.makerguides.com */ // Define to which pin of the Arduino the output of the LM35 is connected: #define sensorPin A0 void setup() { // Begin serial communication at a baud rate of 9600: Serial.begin(9600); // Set the reference voltage for analog input to the built-in 1.1 V reference: analogReference(INTERNAL); } void loop() { // Get a reading from the temperature sensor: int reading = analogRead(sensorPin); // Convert the reading into voltage: float voltage = reading * (1100 / 1024.0); // Convert the voltage into the temperature in degree Celsius: float temperature = voltage / 10; // Print the temperature in the Serial Monitor: Serial.print(temperature); Serial.print(” \xC2\xB0″); // shows degree symbol Serial.println(“C”); delay(1000); // wait a second between readings }
Sơ đồ đấu nối
Arduino Uno | Cảm biến nhiệt độ LM35 |
VCC | +Vs (4 – 20V) |
GND | GND |
A0 | VOUT |
Các linh kiện cần thiết cho dự án
Tên linh kiện | Số lượng | Shopee |
Arduino Uno R3 | Mua ngay | |
Dây cáp nạp | Mua ngay | |
Cảm biến nhiệt LM35 | Mua ngay | |
Breadboard (Bo test) | Mua ngay | |
Dây cắm (Đực – Đực) | Mua ngay |
Bạn sẽ học được gì
- Có kiến thức cơ bản về Robotics
- Chế tạo Robot dò đường thông minh
- Đánh thức nhà khoa học bên trong bạn
- Tìm hiểu thêm về Robotics, các thuật toán Robot tự động
- Kiến thức nền tảng để chế tạo các máy móc tự động phục vụ đời sống sinh hoạt, lao động sản xuất
- Kiến thức để chế tạo sản phẩm, tham gia các cuộc thi khoa học công nghệ trong nước và quốc tế
How to Measure Temperature
The LM35 is easy to use; just connect the left pin to power (4V to 30V) and the right pin to ground (assuming the flat side of the sensor is facing you). Then the middle pin will have an analog voltage that is directly proportional (linear) to the temperature in °C. This can be easily seen in the output voltage vs temperature characteristic. Note that the analog output voltage is independent of the power supply.
To convert the voltage to temperature, simply use the basic formula:
Temperature (°C) = Vout * 100
For example, if the voltage out is 0.5V that means that the temperature is 0.5 * 100 = 50 °C
Connecting the LM35 Temperature Sensor to an Arduino
Hooking up the LM35 to an Arduino is super simple. You only need to connect three pins: two for power and one for reading the sensor value.
The sensor can be powered from 5V. The positive voltage connects to ‘+Vs’ and ground connects to ‘GND‘. The middle pin ‘Vout’ is the analog signal output from the sensor and connects to the A0 analog input of an Arduino.
Below is the hookup for the experiments with the LM35:
To measure air temperature leave the sensor in the open air or attach it to an object you want to measure the temperature of, such as a heat sink.
Code mẫu
int sensorPin = A0; void setup() { Serial.begin(9600); } void loop() { int reading = analogRead(sensorPin); float voltage = reading * 5.0 / 1024.0; float temp = voltage * 100.0; Serial.println(temp); delay(1000); }
Giải thích Code
reading = analogRead(sensorPin);
Hàm
analogRead()
có nhiệm vụ đọc giá trị điện áp từ một chân Analog (ADC), hàm này luôn trả về 1 số nguyên nằm trong khoảng từ 0 đến 1023 tương ứng với thang điện áp (mặc định) từ 0 đến 5V. Hàm
analogRead()
cần 100 micro giây để thực hiện.
- Xem bài viết kiểu số nguyên int để hiểu thêm.
Vậy
reading = analogRead(sensorPin)
có nghĩa là đọc giá trị điện áp từ cảm biến nhiệt độ LM35.
float voltage = reading * 5.0 / 1024.0;
Công thức tính ra giá trị hiệu điện thế từ giá trị cảm biến (đơn vị Volt) Voltage = giá trị điện áp từ cảm biến chia cho mức analog cao nhất (1024) rồi nhân với mức điện áp 5V.
Như ở trên ta thấy nhiệt độ thay đổi tuyến tính 10mV/°C nên đổi từ Vol sang °C thì ta chỉ cần nhân giá trị điện thế với 100 là ra nhiệt độ.
float temp = voltage * 100.0;
Introduction: Arduino Temperature Sensor Using LM35
Introduction
The LM35 series are precision integrated-circuit temperature devices with an output voltage linearly proportional to the Centigrade temperature. LM35 is three terminal linear temperature sensor from National semiconductors. It can measure temperature from -55 degree Celsius to +150 degree Celsius. The voltage output of the LM35 increases 10mV per degree Celsius rise in temperature. LM35 can be operated from a 5V supply and the stand by current is less than 60uA. The pin out of LM35 is shown in the figure below.
Features
• Calibrated Directly in Celsius (Centigrade)
• Linear + 10-mV/°C Scale Factor
• 0.5°C Ensured Accuracy (at 25°C)
• Rated for Full −55°C to 150°C Range
• Suitable for Remote Applications
• Low-Cost Due to Wafer-Level Trimming
• Operates from 4 V to 30 V
• Less than 60-μA Current Drain
• Low Self-Heating, 0.08°C in Still Air
• Non-Linearity Only ±¼°C Typical
• Low-Impedance Output, 0.1 Ω for 1-mA Load
PinOuts Of LM35 is Shown in image.
You can download the datasheet from below file.
Supplies
Hardware components
LM35 analog temperature sensor (TO-92) | × 1 | Amazon |
Arduino Uno | × 1 | Amazon |
Breadboard | × 1 | Amazon |
Jumper wires | ~ 10 | Amazon |
16×2 character I2C LCD | × 1 | Amazon |
USB cable type A/B | × 1 | Amazon |
Software
Arduino IDE |
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. As an Amazon Associate we earn from qualifying purchases.
Testing the LM35 Sensor
Testing the LM35 is pretty easy, just connect the left pin to 4V to 30V power supply (Four AA batteries work great) and the right pin to ground (assuming the flat side of the sensor is facing you). Now connect your multimeter in DC voltage mode to ground and the middle pin. At the room temperature (25°C), the voltage should be about 0.25V.
Try squeezing the plastic case of the sensor gently to see a rise in temperature.
Or try touching the sensor with an ice cube (in a plastic bag so your circuit doesn’t come into contact with water) and watch the temperature drop.
Wiring – Connecting LM35 analog temperature sensor to Arduino
Connecting an LM35 to the Arduino is very easy as you only need to connect 3 pins. Start by connecting the +VS pin to the 5 V output of the Arduino and the GND pin to the ground.
Next, connect the middle pin (VOUT) to any of the analog inputs of the Arduino. In this case, I used the analog input pin A0.
The connections are also given in the table below:
LM35 analog temperature sensor connections
LM35 | Arduino |
Pin 1 (+VS) | 5 V |
Pin 2 (VOUT) | Pin A0 |
PIN 3 (GND) | GND |
About the LM35
The LM35 is an inexpensive, precision Centigrade temperature sensor made by Texas Instruments. It provides an output voltage that is linearly proportional to the Centigrade temperature and is, therefore, very easy to use with the Arduino.
The sensor does not require any external calibration or trimming to provide accuracies of ±0.5°C at room temperature and ±1°C over the −50°C to +155°C temperature range.
One of the downsides of the sensor is that it requires a negative bias voltage to read negative temperatures. So if that is needed for your project, I recommend using the DS18B20 or TMP36 instead. The TMP36 by Analog Devices is very similar to the LM35 and can read temperatures from -40°C to 125°C without any external components.
You can find a dedicated tutorial for the TMP36 and DS18B20 here:
- TMP36 analog temperature sensor with Arduino tutorial
- The complete guide for DS18B20 digital temperature sensors with Arduino
The output scale factor of the LM35 is 10 mV/°C and it provides an output voltage of 250 mV at 25°C (see Figure below).
Note that the sensor operates on a voltage range of 4 to 30 V and that the output voltage is independent of the supply voltage.
The LM35 is part of a series of analog temperature sensors sold by Texas Instruments. Other members of the series include:
- LM335 – output voltage directly proportional to the absolute temperature at 10 mV/°K.
- LM34 – output voltage linearly proportional to Fahrenheit temperature 10 mV/°F.
LM35 pinout
The LM35 comes in 4 different packages, but the most common type is the 3-pin TO-92 transistor package.
The pinout of the sensor is as follows:
Note that pin 1 (+VS) is the leftmost pin when the flat side of the sensor (with the text printed on it) is facing towards you.
Name | Pin | Description |
+VS | Positive power supply pin (4 – 30 V) | |
VOUT | Temperature sensor analog output | |
GND | Device ground pin, connect to power supply negative terminal |
You can find the specifications of the LM35 in the table below.
LM35 analog temperature sensor specifications
Supply voltage | 4 V to 30 V |
Operating current | 60 µA |
Temperature range | -55°C to + 155°C |
Ensured accuracy |
±0.5°C at +25°C
±1°C from -55°C to +150°C |
Output scale factor | 10 mV/°C |
Output voltage at 25°C | 250 mV |
Self-heating | <0.1°C in still air |
Package | 3-pin TO-92 |
Manufacturer | Texas Instruments |
Cost | Check price |
For more information, you can also check out the datasheet here:
Reading the Analog Temperature Data
As you can see in the wiring diagram above, the output of the LM35 is connected to one of the analog inputs of the Arduino. The value of this analog input can be read with the
analogRead()
function.
However, the
analogRead()
function does not actually return the output voltage of the sensor. Instead it maps the input voltage between 0 and the ADC reference voltage (technically it is the operating voltage i.e. 5V or 3.3V unless you change it) to 10-bit integer values ranging from 0 to 1023. To convert this value back to the sensor’s output voltage, use this formula:
Vout = (reading from ADC) * (5 / 1024)
This formula converts the number 0-1023 from the ADC into 0-5V
Then, to convert volts into temperature, use this formula:
Temperature (°C) = Vout * 100
Cảm biến nhiệt độ LM35
- LM35 là một cảm biến nhiệt độ Analog (A0 đến A5 trên board Arduino Uno).
- LM35 không cần phải canh chỉnh nhiệt độ khi sử dụng.
- LM35 thay đổi nhiệt độ nhanh và chính xác.
Cảm biến nhiệt độ LM35 là bộ cảm biến nhiệt mạch tích hợp chính xác cao mà điện áp đầu ra của nó tỷ lệ tuyến tính với nhiệt độ theo thang độ Celsius.
Thông số kỹ thuật của cảm biến:
- Điện áp hoạt động: 4-20V DC.
- Công suất tiêu thụ: 60uA.
- Khoảng đo nhiệt độ: -55°C đến 150°C.
- Nhiệt độ thay đổi tuyến tính: 10mV/°C.
- Độ chính xác thực tế: 1/4°C ở nhiệt độ phòng và 3/4°C ngoài khoảng 2°C tới 150°C.
Cảm biến LM35 hoạt động bằng cách cho ra một giá trị hiệu điện thế nhất định tại chân Vout (chân giữa) ứng với mỗi mức nhiệt độ.
Đo nhiệt độ bằng Cảm biến LM35 sử dụng Arduino Uno
Hôm nay chúng ta sẽ cùng nhau tìm hiểu về cách sử dụng cảm biến nhiệt độ LM35.
Cảm biến có ưu điểm hoạt động khá chính xác và ít sai số đồng thời kích thước nhỏ, giá thành thấp nên được sử dụng rất nhiều trong các ứng dụng đo nhiệt độ thời gian thực.
Qua bài viết này, các bạn sẽ tìm hiểu thêm một hàm mới là analogRead().
- Đọc bài viết về hàm analogRead(pin).
Conclusion
In this tutorial, I have shown you how to use an LM35 analog temperature sensor with Arduino. I hope you found it useful and informative. If you did, please share this article with a friend who also likes electronics and making things.
I would love to know what projects you plan on building (or have already built) with this sensor. If you have any questions, suggestions, or if you think that things are missing in this tutorial, please leave a comment below.
Note that comments are held for moderation to prevent spam.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Working Principle
The LM35 uses a solid-state technique to measure the temperature. It makes use of the fact that the voltage drop between the base and emitter (forward voltage – Vbe) of the Diode-connected transistor decreases at a known rate as the temperature increases. By precisely amplifying this voltage change, it is easy to generate an analog signal that is directly proportional to temperature.
This linear relationship between forward voltage and temperature is the reason why diode-connected transistors are used as temperature measurement devices. Essentially this is how temperature is measured, although there have been some improvements in this technique over the years. More information about this technique can be found here.
The good news is that all these complex calculations are done inside the LM35. It just outputs a voltage that is linearly proportional to temperature.
LM35 Sensor Pinout
The LM35 comes in three different form factors, but the most common type is the 3-pin TO-92 package, which looks just like a transistor. Let’s take a look at its pinout.
+Vs is the power supply for the sensor which can be anywhere between 4V to 30V.
Vout pin produces an analog voltage that is directly proportional (linear) to the temperature. It should be connected to an Analog (ADC) input.
GND is a ground pin.
Step 2: Programming the Arduino
/*Code designed by Sujay Alaspure in SA Lab */
const int sensor=A5; // Assigning analog pin A5 to variable ‘sensor’
float tempc; //variable to store temperature in degree Celsius
float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading
void setup() {
pinMode(sensor,INPUT); // Configuring sensor pin as input
Serial.begin(9600);
void loop() {
vout=analogRead(sensor); //Reading the value from sensor
vout=(vout*500)/1023;
tempc=vout; // Storing value in Degree Celsius
tempf=(vout*1.8)+32; // Converting to Fahrenheit
Serial.print(“in DegreeC=”);
Serial.print(“\t”);
Serial.print(tempc);
Serial.print(” “);
Serial.print(“in Fahrenheit=”);
Serial.print(“\t”);
Serial.print(tempf);
Serial.println();
delay(500); //Delay of 1 second for ease of viewing }
Step 3: Output Result
See the result on Serial Moniter….
First of all, I would like to thank you for reading this guide ! I hope it helps you.
If You have any queries I am happy to help you…..
Drop a Comment. Your feedback is valuable for me.
Participated in the Arduino Contest 2017
One of the easiest and inexpensive ways to add temperature sensing in your Arduino project is to use LM35 Temperature Sensor. These sensors are fairly precise and needs no external components to work. So, with just a few connections and some Arduino code you’ll be sensing temperature in no time!
Converting the LM35 output voltage into temperature
To convert the output voltage of the sensor into the temperature in degree Celsius, you can use the following formula:
Temperature (°C) = VOUT / 10
with VOUT in millivolt (mV). So if the output of the sensor is 750 mV, the temperature is 75°C.
As you can see in the wiring diagram above, the output of the LM35 is connected to one of the analog inputs of the Arduino. The value of this analog input can be read with the function analogRead(). However, this function will not actually return the output voltage of the sensor.
Arduino boards contain a multichannel, 10-bit analog to digital converter (ADC), which will map input voltages between 0 and the operating voltage (5 V or 3.3 V) into integer values between 0 and 1023. On an Arduino Uno, for example, this yields a resolution between readings of 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit.
So if you use analogRead() to read the voltage at one of the analog inputs of the Arduino, you will get a value between 0 and 1023.
To convert this value back into the output voltage of the sensor, you can use:
VOUT = reading from ADC * (Vref / 1024)
We will use these formulas in the code examples below.
Arduino Project – Standalone Thermometer with LM35 and an I2C LCD
Sometimes you come up with an idea where you want to display the temperature readings in real time and show an alert when the temperature is outside the specified range. Then you’ll probably need a 16×2 character LCD instead of a serial monitor.
In this example, we’ll hook the I2C LCD up to the Arduino along with the LM35.
Connecting the I2C LCD is quite easy as you can see in the wiring diagram below. If you’re not familiar with an I2C LCDs, consider reading (at least skimming) below tutorial.
The following diagram shows you how to wire everything.
The following sketch will print the temperature values on the I2C LCD. The code is similar to the previous example, except that the values are printed on the I2C LCD.
// Include the LiquidCrystal_I2C library #include// Create a new instance of the LiquidCrystal_I2C class LiquidCrystal_I2C lcd(0x3F, 16, 2); // Define a custom degree character byte Degree[] = { B00111, B00101, B00111, B00000, B00000, B00000, B00000, B00000 }; // Define the analog pin, the LM35's Vout pin is connected to #define sensorPin A0 void setup() { // Start the LCD and turn on the backlight lcd.init(); lcd.backlight(); // Create a custom character lcd.createChar(0, Degree); } void loop() { // Get the voltage reading from the LM35 int reading = analogRead(sensorPin); // Convert that reading into voltage // Replace 5.0 with 3.3, if you are using a 3.3V Arduino float voltage = reading * (5.0 / 1024.0); // Convert the voltage into the temperature in Celsius float temperatureC = voltage * 100; // Print the temperature on the LCD; lcd.setCursor(0, 0); lcd.print("Temperature:"); lcd.setCursor(0, 1); lcd.print(temperatureC, 1); lcd.write(0); // print the custom degree character lcd.print("C "); // Print the temperature in Fahrenheit float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; lcd.print(temperatureF, 1); lcd.write(0); // print the custom degree character lcd.print("F "); delay(1000); // wait a second between readings }
You should see the following output on the LCD:
In this tutorial, you will learn how to use an LM35 analog temperature sensor with Arduino. I have included a wiring diagram and example codes to help you get started!
In the first part of this article, you can find the specifications and pinout of the LM35. Next, we will look at how to connect the sensor to the Arduino.
The first code example can be used to take temperature readings from the sensor and display the results in the Serial Monitor. In the second example, I will show you how to use the built-in 1.1 V reference voltage of the Arduino to get more accurate readings. Lastly, we will look at how to display the temperature on an I2C LCD to create a standalone thermometer.
If you would like to learn more about other temperature sensors, check out the articles below.
Keywords searched by users: temperature sensor lm35 arduino
Categories: Cập nhật 50 Temperature Sensor Lm35 Arduino
See more here: kientrucannam.vn
See more: https://kientrucannam.vn/vn/