Arduino Nano - LM35 Temperature Sensor
This tutorial instructs you how to use Arduino Nano to read the temperature from LM35 sensor. In detail, we will learn:
- How to connect Arduino Nano to LM35 temperature sensor.
- How to program Arduino Nano to get the temperature from LM35 sensor.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of LM35 Temperature Sensor
The LM35 Temperature Sensor Pinout
The LM35 temperature sensor has three pins:
- GND pin: This should be connected to the ground (0V).
- VCC pin: This should be connected to the VCC (5V).
- OUT pin: This signal pin gives an output voltage that is linearly proportional to the temperature and should be connected to an analog pin on Arduino Nano.
How It Works
The LM35 produces a voltage that is linearly proportional to the Centigrade temperature. Its output scale factor is 10 mV/°C, which means that the temperature can be determined by dividing the voltage (in mV) at the output pin by 10.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
How To Program For LM35 Temperature Sensor
- Obtain the ADC value from the temperature sensor by utilizing the analogRead() function.
- Transform the ADC value into a voltage in millivolts.
- Transform the voltage into Celsius temperature.
- Optional: Convert Celsius to Fahrenheit.
Arduino Nano Code
Detailed Instructions
- Copy the code and open it in the Arduino IDE.
- Click the Upload button in the IDE to send it to your Arduino Nano.
- Hold the sensor in your hand.
- Check out the result on the Serial Monitor.
Improving the Temperature Precision
In the code above, the ADC reference voltage is set to the default value of 5V to 5000mV. To increase the temperature resolution, the reference voltage can be changed to INTERNAL, which is 1.1V to 1100mV, using the analogReference() function.
This table displays the contrast between 5000mV and 1100mV reference voltages.
Vref(mV) | 5000 mV (by default) | 1100 mV (INTERNAL) |
---|---|---|
Reading Resolution | 5000/1024 = 4.88 mV | 1100/1024 = 1.07 mV |
Temperature Resolution | 0.488 °C | 0.107 °C |
Temperature Range | 0 to 500 °C | 0 to 110 °C |