Introduction: Arduino and LM35 Based Temperature Monitor for Beginners

Introduction

Make your own temperature monitoring system by using Arduino and LM35 analog temperature sensor. This is a very simple DIY project for the Arduino beginners. All the steps and requirements are mentioned in detail below.

Note:- This tutorial is intended for the absolute beginners only. Experienced persons may find many of the steps as not relevant to them.

Step 1: Requirements

Hardware Requirements

1) Any Arduino board with analog input pin. ( Here I used Arduino Uno )

2) LM-35 Temperature sensor ( http://www.ti.com/lit/ds/symlink/lm35.pdf )

3) Breadboard for assembling the sensor set up

4) USB cable as per the Arduino board specification (Arduino Uno uses USB 2.0 Type A <=> Type B cable)

5) Connecting wires

6) External Power Supply - Not required as the Arduino and Sensor draws power from the USB port connected to PC/Laptop

Software Requirements

1) A PC/Laptop ( Mac/Windows/Linux )

2) Arduino Software (Install from https://www.arduino.cc/en/Main/Software as per your PCs Operating system )

Step 2: Make the Hardware Setup Ready

1) Identify the Power and Analog inputs of the Arduino board

2) Understand the Pin configuration of the LM35 temperature sensor

3) Connections are mentioned below

Arduino <=> LM-35

Analog In / A0 <=> Pin 2 /Middle/Data pin

Power / 5v <=> Pin 1

Power / GND <=> Pin 3

4) Connect the Arduino board to the PC using the USB cable

Step 3: Make the Software Setup Ready

1) Install the Arduino IDE/Software mentioned in Step 1/ Software Requirements

2) Connect the Arduino board to the PC/Laptop using USB cable

3) Go to your PC/Laptops Device Manager => Ports and note in which port Arduino is connected

4) In the Arduino IDE, go to Tools => Port and connect to the Port where Arduino is connected

5) In the Arduino IDE, go to Tools => Board. Make sure that the selected board is same as what you use

5) Create a new file in the IDE and write your program there. [ You can refer Step-4 Understanding The Program/Sketch ]

Step 4: Understanding the Program/Sketch

The program is self explanatory as comments are added for each line. The constant [ 0.48875855 ] used for converting the sensor voltage to Degree Celsius is explained in the next step.

The sketch is attached for your reference [ LM-35_Analog_Temp.ino ]

Compile and flash the program in the Arduino board

Step 5: The Magic Number 0.48875855 Is Explained

Arduino has an analog-to-digital converter (ADC) that reads the values which are being received in the analog pins (Pins from A0 - A5) and converts them to a number between 0 and 1023.

analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the analog input pin.

Here the voltage applied to the sensor is 5v. The sensor output scales between 0.0 and 5.0.

To scale the numbers between 0.0 and 5.0, divide 5.0 by 1023.0 and multiply that by sensor value :

ie sensor value * (5v/1023) = sensor value * (5000 mv/1023) = sensor value * 4.8875855

The scale factor in LM35 is 10mv /°C

ie sensor value * (4.8875855 / 10) = sensor value * 0.48875855

Please refer to the manuals of Arduino and LM35 for more details

Step 6: Program Execution and Temperature Monitoring

Refer step 4 for the compilation and flashing of the program.

Compile and flash your program in Arduino.

In the Arduino IDE go to Tools => Serial Monitor. This will open up the console for printing the data from Arduino. The measured temperature is displayed here.

Step 7: Debugging / Troubleshooting

The common problems are

1) The Arduino IDE is unable to connect to the Board

Check all the connections physically and select the correct port after referring to device manager in PC

Make sure that the Arduino board selected in Tools => Board is same as the one that you are using

2) Temperature measured is not correct

Cross check your sketch with my sketch

Using a multi-meter measure the voltage between Pin 2 & 3 of the LM35 sensor. This (voltage/10) will be approximately same as the final temperature displayed by Arduino in the Serial Monitor. This way we can verify whether the sensor is working fine or not.

Step 8: Conclusion

Hope you have made your home temperature monitor by this time :-) . You can start your home automation now.

I will be back soon with more fun with Arduino.

Comments

author
druid001 made it!(author)2016-06-16

I'm just learning the coding. How can I change the code to show 'F instead of 'C?

author
Aby+Kuriakose made it!(author)2016-06-16

In my example insert the below line after line 18

Temperature = (Temperature * 1.8) + 32;

In line 21 replace C with F

Refer https://en.wikipedia.org/wiki/Fahrenheit for more details about the constants used for conversion

author
Eric+Brouwer made it!(author)2016-06-15

Thanks for sharing.


Here is a tip to dramatically increase the accuracy of your LM35 readings:


- By default, the Arduino A/D converter reference voltage is set to +Vcc. This is normally in the range of 5V, but does change with loading and supply source.

0V will be read as 0, and 5V will be read as 1023 by the A/D.

- With 5V reference, the Arduino can technically read temperatures up to 500 degrees C, but this is out of the LM35 specs.

- Temperature resolution with a 5V A/D reference is around 0.5 degrees C per step.

- At 25 degrees, the A/D reading will be 51, and at 26 degrees 53.

Now, is there a way to increase the accuracy, without changing the hardware?

Yes, we can do that by changing the A/D reference voltage.

- By adding the command analogReference(INTERNAL); under the setup()

void setup(){

Serial.begin(9600);

AnalogReference(INTERNAL); // Add this line

}

- This code tells the Arduino to use the 1.1V internal voltage reference inside the ATMega328p chip, instead of +Vcc (or 5V).

- Now, 0V will be read as 0, and 1.1V will be read as 1023 by the A/D.

- Thus, you can now read from 0 degrees C to 110 degrees C with the LM35.

- Temperature resolution with the 1.1V reference is now 0.107 degrees C per step.

- At 25 degrees, the A/D reading will now be 232, and at 26 degrees 241.

All that is left to do, is to change your constant of 0.48875855 to 0.10752688.

Change this line

Temperature = sensorTemp * 0.48875855; //(+Vcc * 1000 / 1023) / 10

to

Temperature = sensorTemp * 0.10752688; //(1.1V * 1000 / 1023) / 10

Hope this info will be helpful.

Regards

author
Aby+Kuriakose made it!(author)2016-06-15

Thanks a lot Eric for this explanation

author
Eric+Brouwer made it!(author)2016-06-15

It's a pleasure.

author
tomatoskins made it!(author)2016-06-14

This is some great information! Thanks for sharing your project!

About This Instructable

2,703views

23favorites

License:

Bio: Developing Mobile Handset Software for the past 12 years.
More by Aby Kuriakose:Arduino And LM35 Based Temperature Monitor For Beginners
Add instructable to: