Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Electronics and Computer Engineering
========================================================================
TITLE: Experiment Write-up (EW)
Doc. No.: IoT/SOP/EW/03(08)
Experiment No. 03
Temperature Display
Aim: -
Interfacing temperature sensor LM35 with Arduino board & program to display temperature.
Learning Objectives: -
To understand interfacing of analog as well as digital input & output devices with the Arduino
board.
Equipments required:
Arduino Uno, LM35 temperature sensor, some connecting wires, A to B USB cable, PC with
Arduino IDE installed in it.
Theory: Explain: -
What is LM35?
LM35 Pin out with diagram
Arduino Uno
Following Function of arduino sketch along with syntax and IO parameters
pinMode
analogRead
Serial.begin
Serial.println
Block Diagram: -
Figure 1. Schematic diagram
Procedure:
CONNECTION:
Connect V pin of sensor (Vcc) to 5V pin of Arduino Uno.
Connect GND pin of the sensor with GND of Arduino Uno.
Interface OUT pin of sensor with A0 pin of Arduino Uno.
Prepared By Approved By
Prof. G. A. Bhatane Dr. B. S. Agarkar
Subject Incharge HOD ECE
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Electronics and Computer Engineering
========================================================================
TITLE: Experiment Write-up (EW)
Doc. No.: IoT/SOP/EW/03(08)
TESTING:
1. Connect the A to B cable to the USB port of a computer & make sure that the port has been
detected by checking the Device Manager option.
2. Open Arduino IDE window & select Arduino UNO as Board in tools [Board: Tools > Board >
Arduino/Geniuno UNO].
3. Now select the appropriate COM port again in tools [Tools > Port in Arduino].
4. Create new sketch, type program.
5. Compile & upload this program to your Arduino uno board via Arduino IDE by clicking on
upload button.
6. Readings from the sensor will be obtained in the serial monitor.
Observation Table: -
Sr. No. Actual Temperature Observed Temperature
1
2
3
Calculations of Conversion Factor: -
Input range= 0V to 5V Reference Arduino Datasheet
Output range=0 to 1023(210=1024) Reference ATMEGA 328P Datasheet
Step size= 10mV change for each 1oC change in temperature Reference LM35 Datasheet
Formula Conversion Factor (cf)=
cf=
cf=0.48828
Sketch / Program: -
float temp;
void setup()
{Serial. Begin (9600);
}
void loop()
{
temp = analogRead(A0);
temp = temp * 0.48828125; //0.48828= (5*100/1023)
Serial.println(temp);
delay (1000);
}
Or
Another Sketch/Program
// Define the analog pin, the LM35's Vout pin is connected to
#define sensorPin A0
Prepared By Approved By
Prof. G. A. Bhatane Dr. B. S. Agarkar
Subject Incharge HOD ECE
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Electronics and Computer Engineering
========================================================================
TITLE: Experiment Write-up (EW)
Doc. No.: IoT/SOP/EW/03(08)
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
}
Code Explanation:
The sketch starts by defining the Arduino pin to which the sensor’s Vout pin is connected.
#define sensorPin A0
In 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 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.
Prepared By Approved By
Prof. G. A. Bhatane Dr. B. S. Agarkar
Subject Incharge HOD ECE
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Electronics and Computer Engineering
========================================================================
TITLE: Experiment Write-up (EW)
Doc. No.: IoT/SOP/EW/03(08)
the setup, we initialize the serial connection with the computer.
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");
Conclusion: -
References: -
https://www.arduino.cc
Prepared By Approved By
Prof. G. A. Bhatane Dr. B. S. Agarkar
Subject Incharge HOD ECE