Temperature Sensor Lab - the Department of Electrical and Systems

advertisement
UNIVERSITY OF PENNSYLVANIA
DEPARTMENT OF ELECTRICAL AND SYSTEMS ENGINEERING
ESE UNDERGRADUATE LABORATORY
ESE 205: Electrical Circuits and Systems I 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.
2.
3.
4.
Arduino board
USB Cable
LM 34, temperature sensor
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 the
temperature is 73°F. 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
document1, eselabs@seas.upenn.edu
Figure 2: Arduino Board
Page 1 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
Arduino
GND +5V GND 12 GND 11 Board
-
-
-
5
4
3
2
16
+5V GND
Figure 4: 16X2 Liquid Crystal Display
LCD Display library functions are used interface the Digital I/O pins of the Arduino board with
the LCD Display. ‘lcd.print(“xxxxx”)’ function is used to display the measured values. Refer to
the 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
document1, eselabs@seas.upenn.edu
Page 2 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 <LiquidCrystal.h>
// 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;
document1, eselabs@seas.upenn.edu
Page 3 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.
ii.
iii.
Explain how is temperature data acquired from the sensor using the Arduino board?
What are the maximum and minimum values of temperature you can measure using
the Arduino board?
Can you display the temperature in oC and K?
Figure 5: Measurement of temperature using Arduino board
GOOD LUCK!
document1, eselabs@seas.upenn.edu
Page 4 of 4
Download