Transforming Ideas into Innovations II-ENGR132
Arduino 2: Temperature Monitoring System
Lab Agenda
1. Temperature Monitoring System Example
2. Practice Exercise
ENGR 132
Temperature monitoring example
Example Project
Develop an Arduino project for temperature
monitor using LM35 temperature sensor
and an LED.
Read the temperature and display it on the
computer. If the temperature reading is
higher than 24°C , the LED will blink.
Otherwise, the LED will be off.
Note:To convert the analog signal from LM35
sensor to °C use the following equation
(5.0∗𝑟𝑒𝑎𝑑𝑖𝑛𝑔∗100.0)
Temperature(°C )=
1023
Step 1: Flowchart
Start
Read Signal
Calculate
temperature
Display
temperature
If Yes Turn LED ON Wait Turn LED OFF Wait
Temp.>24
No
Turn LED OFF
Step 2: Wiring
Step 3: Coding
Define Constants & Variables
//LM35 Pin Variables
const int ledPin = 9; // LED Pin connected to pin 9
const int sensorPin = A0; // Temp sensor (LM35) Vout is connected to pin A0
int reading; // New variable named reading to store reading from sensor
float temperatureC; // New variable named temperatureC of type float
Define Inputs & Outputs
void setup()
{
pinMode(ledPin, OUTPUT); // Set pin 9 as OUTPUT
pinMode(sensorPin, INPUT); // Optional: as all Analog pins are input in UNO
Serial.begin(9600); // begin serial connection with the computer to
} // view sensor readings on the monitor
Step 3: Coding
Code for your Program Loop
void loop()
{ reading = analogRead(sensorPin); // read data from LM35 using Arduino (A0) pin
temperatureC = (5.0 * reading* 100.0) / 1023.0; // Convert reading to temp
Serial.println(temperatureC); // Print voltage on serial monitor
if(temperatureC>24) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
else{
digitalWrite(ledPin, LOW);
}
}
Step 4: Upload your Code
ENGR 132
Practice Exercise
Temperature Monitoring
Develop an Arduino project for temperature
monitor using LM35 temperature sensor, red LED
and green LED.
Read the temperature and display it on the
computer. If the temperature reading is less than
25°C , the green LED will blink. Otherwise, the
red LED will blink.
Note:To convert the analog signal from LM35
sensor to °C use the following equation
(5.0∗𝑟𝑒𝑎𝑑𝑖𝑛𝑔∗100.0)
Temperature(°C )=
1023