You are on page 1of 6

TEE 451 - Control Systems

Winter 2021

Instructor: Michael McCourt Assignment: Lab 1


Temperature Identification

1 Introduction to Temperature Identification Lab


In the control design process, the first step is to fit a model for the system you want to control. This
involves using physical principles and data collection. This lab is focused on collecting data in order to
characterize a first order system response. The system of interest is a temperature control system that
consists of a thermoelectric Peltier heater and a small metal block. The thermoelectric heater works as a
heat pump that transfers heat one direction when a positive voltage is applied and the opposite direction
when a negative voltage is applied. You can read more about how a thermoelectric heater works.
https://en.wikipedia.org/wiki/Thermoelectric_cooling
We want to control the temperature of the metal block by varying the voltage across the Peltier heater.
When a positive voltage is applied, the temperature will rise until the heat lost to the environment balances
with the heat being generated. While the exact diffusion of heat through the block and into the air is a
complicated process, we can approximate the temperature at a given point on the block as a first order
system. The response of the system can be seen in the equation below and Figure 1. The value of τ is
the system time constant that needs to be identified and the values of the constants C1 and C2 depend
on the initial temperature and steady state temperature.

y(t) = C1 − C2 e−t/τ

C1
f(t)

C 1 -C2

Figure 1: First order system response to a constant input.

For this lab, you will use a pulse-width-modulated (PWM) signal on the Arduino. A PWM signal is
a square wave with a fixed frequency. The duty cycle is the percentage of time that the signal is high.
The Arduino PWM period is approximately 2 ms. If the PWM signal is high (5V) for 0.5 ms and low
(0V) for 1.5 ms, this is a 25% duty cycle. For this lab, the duty cycle will be fixed at 80%, but in Lab 2
this will be a variable.

page 1 of 6
Control Systems Winter 2021

2 Lab Safety
This lab has potential safety concerns due to electric current and elevated temperatures. When the power
adapter is connected, make sure to not touch any wires or circuit components as there is a risk of electric
shock. Before touching circuit components, make sure to disconnect the power adapter. When the power
adapter is connected, be careful when handling the thermoelectric Peltier heater, the metal block, and
the temperature sensor as they may be hot. Do not leave any part of the circuit or temperature control
system running when you are not present in the room. If you must leave the room, you can unplug the
power adapter which eliminates most risks. Finally, be careful when handling parts with sharp edges
including the metal blocks and the pins on integrated circuits.

3 Temperature Test Circuit


In this lab, you will use the L293D motor driver. While the Arduino is a useful tool, it cannot supply
enough current to power the thermoelectric heater. The motor driver acts as a relay that is enabled by
the Arduino, but the actual current through the heater is supplied by the 5V power adapter. There are
some benefits to the circuit we will be using (Figure 2). For example, you can supply both positive and
negative currents by using two PWM signals from the Arduino. When the two PWM signals are the same
(either high or low) no current will flow through the heater. When the first PWM signal is high and the
second PWM signal is low, current will flow in one direction. When the first PWM signal is low and the
second PWM signal is high, current will flow in the opposite direction. You can find more information
and the datasheet for the motor driver at the following link.
https://www.adafruit.com/product/807

1. Build the circuit in Figure 2 with the motor driver, four 1N4007 diodes, Peltier cooler (indicated
with a P in a circle), and 5V power adapter. Note that the voltage at pins 2 and 7 will be controlled
by the PWM signals coming from the Arduino, but the current through the Peltier (pins 3 and 6)
is actually supplied by the 5V power adapter.

2. Connect Vcc1 to the 5V supply on the Arduino. Connect Vcc2 to the 5V supply from the 5V
power adapter using the barrel jack to bare wire adapter. The two sources must have their grounds
connected together.

3. Make sure to connect all pins as indicated. There are four pins that must be grounded.

4. Connect pin 1 to the 5V source coming from the Arduino. This is an enable input that must be
high to enable the motor driver.

5. With this circuit, the maximum current in the circuit will near 500 mA. It is important to never
touch the circuit components or wires when the power is connected.

6. Attach jumper cables to the TMP36 as extensions to the pins. The power supply for the TMP36
should be connected to 5V source coming from the Arduino.
https://learn.adafruit.com/tmp36-temperature-sensor

7. Use electrical tape to tape the sensor to the block and the block to the Peltier cooler.

page 2 of 6
Control Systems Winter 2021

Figure 2: The motor driver can be connected in this way to power the thermoelectric heater.

4 Using the Arduino in MATLAB


For this part, you will integrate the Arduino with MATLAB in order to collect readings in MATLAB for
plotting and saving.

1. If you havent already, you need to add a package to MATLAB. On the “Home” menu click “Add-
ons”. You need to add the specific package “MATLAB Support Package for Arduino Hardware”.
https://www.mathworks.com/help/supportpkg/arduino/ug/install-support-for-arduino-
html

2. Connect your Arduino to your computer using the USB cable. Run the line a = arduino. MATLAB
should connect to the Arduino and display the device name and COM port.

3. Run the line methods(a) to see the functions available

4. We will use the function configurePin() to set a digital pin to be a PWM signal. You will need to
specify the variable for the Arduino device (a), the pin to be the PWM signal (e.g. ‘D8’ in single
quotes), and the third parameter is ‘PWM’ in single quotes.

5. You will use the function writePWMDutyCycle() to set the PWM cycle. You will need to specify
the Arduino device, the PWM pin, and the duty cycle between 0 and 1 (representing 0% to 100%).
Note that the PWM signal switches from 0V to 5V with a frequency of 490 Hz.

6. Test these functions to be sure that you can set a PWM signal and read temperature sensor values.
You should be able to heat the block by setting one PWM pin high (1) and the other low (0). You
can identify which pin heats the block when it is high (“heating pin”) and which pin cools the block
when it is high (“cooling pin”). If you wish to switch the two pins, you can swap their connections
to the motor driver at pins 2 and 7.

page 3 of 6
Control Systems Winter 2021

5 Temperature Sensor Calibration


The temperature readings are not accurate when you first use the TMP36 sensor. You can correct for this
by taking measurements and calibrating your temperature sensor using a trusted sensor. As you may or
may not have access to a thermometer at home, you have two options for the calibration for the sensor.
If you have any sort of digital thermometer, I recommend proceeding with Option 1. If you do not, you
must go with Option 2. While Option 2 will give you credit for the lab, the temperature may not be
accurate.
Option 1

1. Review your work on the Arduino Tutorial using the TMP36 temperature sensor. Connect the
temperature sensor to your Arduino.

2. Initially, keep the power adapter disconnected so that you can measure the temperature of the metal
block at room temperature.

3. Write a MATLAB script that collects temperature data points from the Arduino for 10-20 seconds.
Run this script and average across all values collected.

4. At the same time, measure the current temperature in Fahrenheit using the thermometer you have
available. If the temperature changes during the time, average the min and max temperatures to
get an approximate average. This voltage and temperature pair is your first calibration point.

5. Connect the power adapter. Configure the two PWM pins so that the heater heats the metal block.
◦ ◦
6. Allow the metal block to heat to a temperature in the range of 80 F to 90 F. Record the voltage
and temperature. This is your second calibration point.

7. Using these two points, find a linear equation that maps voltage measurements to an accurate
temperature value. Only the line slope and vertical intercept are needed. You will use this line as
a conversion to temperature.

8. The calibration may not be accurate over time so I recommend repeating the calibration if you leave
the lab and come back.

Option 2
For this option, you will use a set of sensor voltage readings and corresponding temperature values to
create an equation for temperature calibration. While these values were collected using a TMP36 and a
trusted thermometer, they may or may not be accurate for your specific sensor. The voltage readings are
[0.707, 0.774, 0.841, 0.883, 0.946, 0.961], and the temperature values are [72, 79, 85, 90, 95, 99].

1. Type the voltage readings and temperature values into Matlab as two vectors.

2. Under “Apps” open the “Curve Fitting Tool”. Use the voltage readings as the x-data and the
temperature values as the y-data.

3. Set the fit to linear and find an equation that maps voltage measurements to an accurate temperature
value. Only the line slope and vertical intercept are needed. You will use this line as a conversion
from voltage readings to temperature.

page 4 of 6
Control Systems Winter 2021

6 Data Collection for System Identification


System identification is the act of collecting data and using it to fit a mathematical model of a system.
In this case, the temperature of the metal block over time closely follows a first order system model. To
identify this model, you only need to identify the time constant and system gain. As this is a slow system,
you will need to collect measurements for about 15 minutes in order to characterize the system response.

1. Disconnect the power adapter and allow the system to cool at least 5 minutes before proceeding
with data collection.

2. Select two digital output pins to be used to send signals to the motor driver.

3. For the cooling pin, set the Arduino PWM to 0% duty cycle.

4. For the heating pin, set the Arduino PWM to 80% duty cycle.

5. Create a for loop to collect temperature sensor voltage measurements in a vector.

6. In the loop, you need to record the time of the measurement. This is best done by assuming that
the initial measurement is time zero and each measurement after is some number of seconds since
the starting time. This can be done using the “tic” and “toc” keywords.

7. It is recommended to preallocate the variables for 100000 measurements. This is likely many more
points than needed. However many points you collect over 15 minutes will be sufficient to identify
the system.

8. Run your MATLAB script to collect a vector of sensor measurements and a vector of time values.

9. Use the “save” function to save the sensor readings and time vector as a .mat file.

10. Use your calibration equation to convert these voltage measurements to a temperature in degrees
Fahrenheit.

11. Plot the data over time and save the figure as a .fig file. Make sure to include this in your report.

12. Make sure to set both Arduino PWM signals to 0% duty cycle.

7 Fitting a First-order Model


The goal of this section is to use the data that you collected to identify the system time constant τG and
system gain KG . Knowing both of these values fully specifies the first order transfer function below. As
a note, you will need to pre-process your time and temperature data vectors by removing all zeros at the
end of the vectors. You can do this by creating new vectors and copying the non-zero values of the two
vectors to these new vectors.
KG
G(s) =
1 + τG s

1. Under “Apps” open the “Curve Fitting Tool”. Use your time vector as the x-data and your tem-
perature data for the y-data. Make sure to remove the zeros at the end of each vector before fitting
this curve. Set the fit type to “Exponential” with 2 terms.

page 5 of 6
Control Systems Winter 2021

2. The result of the curve fitting should be two exponential terms with coefficients and exponential
decay rates. One of the decay rates should be much smaller and can be approximated as zero to
give a constant term. The other time constant will be larger and can be used for the exponential
term in the system response below.
y(t) = C1 − C2 e−t/τ

3. You may run into the issue where one of the decay rates isn’t much smaller than the other. In this
case, you will have to manually set the b parameter to zero by clicking “Fit Options”. For this row,
set the max and min values for b both to zero. Look at the remaining variables (a, c, and d) in the
equation and fit them to the equation above for y(t).

4. Finally, to calculate the system gain KG , you can take the maximum difference in temperature and
divide by the voltage supplied. In our case, we are supplying 5V at an 80% duty cycle. We can
approximate this as supplying 4V. With the gain, you can write the transfer function for this first
order system.

8 Lab Report
This lab is the first part of a two part lab. You do not need to write and turn in a lab report for this
lab. Instead, you should document your observations and save your data. You will write a section in your
next lab report that summarizes your work on this lab. You should especially focus on what you did for
sensor calibration and collecting data to fit the first order model. Make sure to save all data, code, and
figures that you generated in this lab. Your lab report will summarize what you did for Lab 1 and Lab 2.

page 6 of 6

You might also like