Objectives
We will predict and measure the time response of a thermal system to a step change in temperature in this lab.
Since you will be working with potentially hazardous items like glue gun, hot water and sensitive equipment like Arduino, computers and temperature sensor, we caution you to be extra careful and attentive to prevent any physical damage to yourself, the equipment or your working environment.
Make sure that you read the instructions carefully and thoroughly before you start the experiment, and follow them!
ASSIGNMENTS/DELIVERABLES
(REPORT DUE TUESDAY, 9/19/2023 AT 1:30 PM ON LAULIMA)
1. Reading
Chapter 4 in the lab textbook (Bingham) on comparing mathematical models to experimental observations.
Useful resources for report writing
2. Answer the following two questions
Each student will answer the following two questions within their lab report. It is important that each student do their own writing. You are encouraged to collaborate with your classmates, but the written answers must be your own. You should focus on the underlying theory and the discussion/analysis of the obtained results. Following are the questions to be answered.
This document should be formatted professionally (Title, your name, class number, sections, subsections, Figure/Table captions, etc.).
Question 1: Compare Model Prediction and Experimental Measurements
Summarize your experimental results and compare the first-order model (from the pre-lab; read Chapter 2 of Models to Measurements: Observing Dynamic Systems by Brian Bingham) with your experimental observations using figures and tables for communication. Describe the results of this comparison in text, making sure to cross-reference the figures in the text. This summary of your results should be a few paragraphs in length and should highlight the most important results of your laboratory. The experimental summary should include:
Visual illustration of you experimental results including the step response graphs.
Qualitative comparisons between your model prediction and experimental results, i.e., what do you observe about the similarities and differences between the mathematical model and the experimental results?
A table summarizing the predicted time constants, measured time constants and fractional difference between predicted and measured values for the various experimental scenarios.
Question 2: Defending a Thesis with Evidence.
Select one of the following assertions to defend in a written paragraph:
"We are able to accurately model the time response of the LM35 temperature sensor with a first-order model."
"The first-order model is not sufficient to accurately capture the behavior of the LM35 temperature sensor."
Write a single paragraph (or two if necessary) that starts with a topic sentence (perhaps one of the two sentences above) and proceeds by providing evidence to support your claim. Strive to make this paragraph as succinct and clear as possible. Likely sources of evidence might include mathematical models, simulations (numerical solutions), and/or experimental evidence. Your paragraph should present a logical argument that uses evidence to substantiate your claim (i.e., the topic sentence). There is no 'right' answer to this question; either statement can be argued with the evidence you have from the lab. Your challenge is to make a compelling, thoughtful case using topics from the class.
Following equipment are required for data collection:
An Arduino Uno board
USB Cable
Temperature sensor (LM35-DT)
Breadboard
Jumper wires
Computer with following software
Arduino IDE
ArduinoScope (MS Windows Only)
Be careful if you are using wire cutters/strippers, to avoid cuts. Never use on a live circuit wire!
Hot glue for insulation is another heat/burn hazard. Be careful while handling. Make sure the sensor is properly insulated after to avoid short-circuit while accidentally dipping the conductive surfaces in water!
To be safe, only submerge the metal tab of the sensor and not the electrical connections! If the sensor is well waterproofed you could submerge the sensor, but it is not advised.
Let the sensor rest for some time after applying glue. Also, do not dip in hot water long enough for the glue to soften/melt, which may expose the electrical connections and cause short-circuit!
Hot water may cause accidental short-circuits or burns if spilled. Be extra careful while handling, as this often happens during these experiments.
You may reset the Arduino after each trial run. If doing so, you will need to re-upload the sketch on the Arduino, and refresh the connection on the ArduinoScope.
The laboratory procedure for this first lab is straightforward, but take time to insure that you get the data acquisition and data processing (MATLAB) working. Take your time! These tools will be used in future labs. Below is a step-by-step procedure for the laboratory exercise.
1. Setup Data Acquisition
Check that your setup from Lab 0 is working properly: You should be able to see from the serial monitor and plotter functions that the Arduino reading acquired from the potentiometer output voltage signal changes smoothly between 0 and 1023 as the knob is turned through its full range.
Set the delay in your Arduino program to 50 (this is the delay per sample in msec).
Output the time of each data sample with Serial.print((millis()/1000.0));
2. Connect Temperature Sensor
We will be using the LM35DT temperature sensor. The datasheet is available here.
The following connections have been made to the LM35DT (see the pinout on page 2 of the LM35DT Datasheet)
The supply voltage (+Vs) is connected to the red wire
The ground (GND) is connected to the black wire
The signal (Vout) is connected to the blue wire
You may apply a small amount of hot glue, silicon, or waterproof tape to waterproof the connections between the wires and sensor if this hasn't been done already.
Make the connections as shown and described below carefully, and verify them before connecting the power cable.
Connect the temperature sensor and the Arduino as shown above (Courtesy). Make sure you get the pins and the connections right before you connect the power!
+Vs of the sensor to +5V of Arduino
GND of the sensor to GND of Arduino
+Vout of the sensor to pin A1 of Arduino
Check that each wire has a secure electrical connection to the Arduino: If the wires are bent or twisted they may be difficulty to insert into the arduino sockets or come loose easily and this will lead to bad data acquisition.
Note: You can use a breadboard setup as shown in the demo figure, but with longer wires. This will allow you to work freely without getting connection interruptions.
** You can skip this part if you are not using an ArduinoScope compatible setup.
Verifying the Operation with ArduinoScope (Windows Only)
Open the ArduinoScope window
Select the appropriate serial port (COM port) with the dropdown box on the right of the application.
Now check the "Connect" box.
Now you should see a trace showing the analog input values.
Notes on operating the ArduinoScope application:
If you start the ArduinoScope application before attaching your Arduino to your PC, you can click the "Refresh Ports" button below the COM port selection box. This should give you a list of all the active COM ports.
Logging data to a text file:
You can use the Pause box or the Run Once button to collect a snapshot of data.
Then click the Save *.txt button to save a series of log files. The log files are given unique names based on the current time on your PC and saved to the same location as the ArduinoScope executable. A separate log file is created for each channel recorded.
Click Tools->Board and Select "Arduino Uno"
Now it is time to compile the code. Click the "verify sketch" button. Check the error console for possible errors.
Upload the sketch to the Arduino by clicking the right-arrow button ("compile and upload sketch to Arduino"). Again check for possible errors.
3. Verifying the Temperature Sensor Operation
To make sure that you are ready to measure temperature with the LM35DT, you should make sure that it is working. One quick way to do this is to simply hold the LM35 in your hand and see that the voltage (as read by the ArduinoScope or in the text output) is slowly rising.
Another debugging approach is to use the handheld multimeter to check the supply voltage (from the Arduino pins) and the output from the LM35DT. If you have a problem with the system, having an independent measurement of the temperature sensor input and output will allow you to determine if the problem is with the Arduino data acquisition module or with the temperature sensor.
The sensitivity of the LM35DT is 10 mV/°C. Estimate the temperature of the LM35DTand compare this to room temperature (20-25 °C).
Connect the Arduino to the computer via USB-cable.
Arduino Code
On your computer, click “File/New” on any Arduino window to start a new file. Type the following code into the new window:
void setup() {
// Start serial port at given baudrate
Serial.begin(9600);
}
void loop() {
Serial.print(millis()/1000.0);
Serial.print(" ");
Serial.println(analogRead(A1));
Serial.flush();
//add a delay (in ms) to sample less frequently
delay(10);
}
Alternate Code (ArduinoScope): Copy and paste the following code to the IDE and save the sketch as "arduinoscope402.ino" in the same folder with the ArduinoScope.exe.
int val;
int tempPin = 1;
void setup(){
Serial.begin(9600);
}
void loop(){
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
float far = (cel*9)/5 + 32;
// Serial.print("TEMPRATURE = ");
Serial.print(celsius);
//Serial.print("*C");
Serial.println();
delay(1000);
Serial.println();
}
Note: You can customize to choose between Celsius and Fahrenheit. Please see the trend and make minor edits as required.
Have three Styrofoam cups ready at this point, one each for hot water (near boiling), cold water (near zero, ice water) and normal temperature tap water. Needless to say, extra attention is required from this point on - with water around the equipment, and hot water in play!
4. Measure Step Response for Heating and Cooling In Still Water: Hot-Cold Water
Prepare two cups of water: one with hot water (near boiling) and one with cold water using ice.
Start data acquisition so that the data is being collected.
Insert the temperature sensor into the cold water and monitor its output as it reaches equilibrium with the water. To be safe, only submerge the metal tab of the sensor and not the electrical connections! If the sensor is well waterproofed you could submerge the sensor, but it is not advised.
Carefully remove the sensor and then insert the probe into the hot water bath. Monitor the temperature rise.
When the probe has reached equilibrium with the hot water, quickly remove the probe and the insert it in the cold water.
Stop the "Autoscroll" in the Serial Monitor when the probe has reached equilibrium with the cold water.
You can copy-paste your acquired data directly into a MATLAB array:
variablename = [ (paste data) ]
*(Alternate option_ Windows Only)* It is also possible to use the ArduinoScope to save data to a file, then import the file into MATLAB. This method has been used in past semesters but is more cumbersome. To do this, pause the ArduinoScope and save the data as a .txt file in the same folder. Give the data file an informative name such as “Lab1_HotCold_trial1.txt”.
Do not include any spaces in your filename! (for MATLAB compatibility)
For example: "Lab1_HotCold_trial1.txt" (Yes!)... "Lab1 HotCold trial1.txt " (No!)
The steps above constitute one run of the experiment. Repeat these steps TWO more times so that you have a total of three experimental runs for the hot-cold transition.
5. Measure Step Response for Heating and Cooling In Still Water: Warm - Room Temperature Water
Repeat step 4, but dilute the hot water so that it is now just “warm”, i.e., somewhere between room temperature and boiling AND replace the cold water with room temperature water.
Save the data and name the files.
Again, repeat the experiment TWO more times so that you have a total of three experiments where you acquire temperature data as the sensor transitions from warm water to room temperature water.
6. Measure Step Response for Cooling In Still Air: Warm Water - Room Temperature Air
Repeat step 4, but instead of cooling the temperature sensor in room temperature water, now cool the sensor completely in still air.
You only need to do this experiment ONCE since it takes some time for the sensor to cool completely.
At this point you should have run a total of seven experiments:
3 experiments recording the transition from hot to cold water.
3 experiments recording the transition from warm to room-temperature water.
1 experiment recording the transition from warm water to room-temperature air.
7. Check Your Data
One of the best things you can do to avoid trouble is to do a quick quality check of your data. Ideally you would do this a few times during the experiment to make sure the measurements you collect for later processing are in good order. You should check your data by making a plot of measured temperature versus time:
Create a folder on your desktop called “Lab_1”. Put all your data files in this folder.
You can plot each set of sampled data vs. time by "plot(variablename(:,1),variablename(:,2)"
Read Section 2.1 of Physical Modeling in MATLAB from Greentea Press here. This is a good reference for systems modeling and MATLAB uses in general.
To obtain plots of temperature vs. time, you need to convert your Arduino sample data to temperature units, with "plot(variablename(:,1),(variablename(:,2)-dataoffset)*scalefactor", taking into account the mV per bit in the data, and the mV/degree sensor sensitivity. (Ref. Ch. 1 of Bingham)
Label plot axes with "xlabel" and "ylabel" commands, give the plot a title with the "title" command.
Adjust and scale plot axes using the "axis" command.
You should be able to now plot the data from all your experimental runs.
**(Alternate option for Windows Only)**
The MATLAB code on the bottom of this webpage is an example of importing and plotting log files (.txt) from the application. Copy an paste the code to MATLAB and save the script as "importArduinoScopeExample.m" in the same folder with the data you just saved. This program allows you to load and visualize the data in MATLAB.
8. Post-Process Your Data
For each heating or cooling event you will need to find the time-constant of the temperature sensor. We will use MATLAB to do this. There are a few ways to estimate the time-constant. The following are suggestions, but there are many other ways to make this estimate:
Plot the temperature versus time for each heating or cooling event (Note: The acquired data is the output voltage from the LM35. This can be converted to a temperature in °C using the sensitivity of the sensor: 10 mV/°C). Based on this plot you can measure the initial and final temperatures. Calculate the temperature that is 63.2% of the way between the initial and final temperatures. From the graph estimate the time difference between the initial start of heating (or cooling) and the time of the temperature that is 63.2% of the way between initial and final.
For the above method, the ginput() MATLAB command is helpful. It allows you to make measurements from a figure window using the mouse. Type help ginput in the command window to learn more.
A slightly more general method is to normalize the temperature values based on the initial and final temperature values. Plotting this normalized temperature can make it easier to identify the time constant.
% Example of importing data from ArduinoScope log file
% The importdata command imports the text data, separated by %commas
fname = 'YourExptFileName.txt';
% data0 includes the time and the amplitude of the signal as %two columns.
data0 = importdata(fname,',');
% Now plot the results
figure(1)
clf();
plot(data0(:,1),data0(:,2),'r')
% Add an expression to convert the voltage output to %temperature (Hint: use the sensitivity of the sensor )
xlabel('----')
ylabel('----')
title('Relevant title')
Note: Since you are familiar with MATLAB and using mathematical expressions by this point, you should be able to add the equation for the unit conversion as suggested in the code and show the end results.