arduinotemp.docx
TRANSCRIPT
-
8/10/2019 ArduinoTemp.docx
1/4
ESE Labs, SEAS, Univ of Pennsylvania, [email protected] Page 1 of 4
UNIVERSITY OF PENNSYLVANIADEPARTMENT OF ELECTRICAL AND SYSTEMS ENGINEERINGESE UNDERGRADUATE LABORATORYSelf Paced Arduino Laboratory
Temperature sensor using the Arduino board
Goal:To measure and display temperature using an Arduino Board interfaced with 16x2 LCD
Display.
Parts Required
1. Arduino board2. USB Cable
3. LM 34, temperature sensor
4. Wires
Procedure:a. Temperature Sensor
LM34 is a 3-pin device with 5V and GND inputs and temperature output. The LM34 is designed
to output 10 mV per degree Fahrenheit, so a reading of 0.73 V on the output pin means thetemperature is 73F. In order to use this on your Arduino you will have to connect the 5V and
GND pins to the corresponding buses on your Arduino, and wire the output pin to an analog
input pin.
Figure 1: Temperature Sensor Figure 2: Arduino Board
-
8/10/2019 ArduinoTemp.docx
2/4
ESE Labs, SEAS, Univ of Pennsylvania, [email protected] Page 2 of 4
b. Display temperature
In order to display the measured temperature values you will have to wire the 16x2 LCD display
(Figure 4) to 6 Digital Output pins of the Arduino board.
Wire the pins according to the following assignments:
LCD 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Arduino
BoardGND +5V GND 12 GND 11 - - - - 5 4 3 2 +5V GND
Figure 4: 16X2 Liquid Crystal Display
LCD Display library functions are used interface the Digital I/O pins of the Arduino board withthe LCD Display. lcd.print(xxxxx) function is used to display the measured values. Refer tothe above code.
c. Compile and download the working code to the Arduino Board
Compile the following code in Arduino IDE and download it to the Arduino Board.
/*
TempSensor - University of Pennsylvania
Uses the LiquidCrystal Library to display
the real time temperature in deg. F using
the LM34 IC
The circuit:
* LCD RS pin to digital pin 12
-
8/10/2019 ArduinoTemp.docx
3/4
ESE Labs, SEAS, Univ of Pennsylvania, [email protected] Page 3 of 4
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 7
* LCD D5 pin to digital pin 8
* LCD D6 pin to digital pin 9
* LCD D7 pin to digital pin 10
*/
// include the library code:
#include
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5,4,3,2);
float tempVal;
float sensorVal;
int sensorPin = 4;
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Temp (deg. F)");
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
lcd.clear();
// get temperature
sensorVal = (analogRead(sensorPin)/1023.0)*5.0;
tempVal = sensorVal*100.0;
-
8/10/2019 ArduinoTemp.docx
4/4
ESE Labs, SEAS, Univ of Pennsylvania, [email protected] Page 4 of 4
delay(100);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.print("Temp (deg. F):");
lcd.setCursor(0, 1);
lcd.print(tempVal);
delay(1000); //0.5sec
}
d. Questions:
i. Explain how is temperature data acquired from the sensor using the Arduino board?
ii. What are the maximum and minimum values of temperature you can measure using
the Arduino board?iii. Can you display the temperature in
oC and K?
Figure 5: Measurement of temperature using Arduino board