A mini-project to build a system to automatically measure temperature. Topics include:
Before the lab, do anything (e.g. design, analyze, read, watch, …) that can be done before the lab.
Unless a high current is needed, it is best to set the current limit on your supply to <50ma, to reduce that chance that components will be damaged if circuits are miswired.
The Arduino is easy to fry due to static. BE CAREFUL!!
Arduino analog input pins are electronically fragile and can sometimes fail in ways that are not immediately obvious.
A thermistor is a resistor whose resistance (\(R_t\)) depends on temperature as shown in Figure 1. You will be using a Vishay NTCLE100E3103HB0 thermistor](http://www.farnell.com/datasheets/2792960.pdf), an NTC type with a negative temperature coefficient, i.e., its resistance decreases with temperature. Its nominal resistance at \(25^\circ\mathrm{C}\) is \(R_{25} = 10 \mathrm{k}\Omega\).
The thermistor’s datasheet provides the following formula for converting its resistance to temperature in Kelvin:
\[\frac{1}{T(R_t)} = A_1 + B_1\ln\frac{R_t}{R_{25}} + C_1\left(\ln\frac{R_t}{R_{25}}\right)^2 + D_1\left(\ln\frac{R_t}{R_{25}}\right)^3 \]
The constants for this thermistor type (in units of \(K^{-1}\)) are \(A_1 = 3.354016 \times 10^{-3}\), \(B_1 = 2.884193 \times 10^{-4}\), \(C_1 = 4.118032 \times 10^{-6}\), \(D_1 = 1.786790 \times 10^{-7}\).
Resistance versus temperature for a negative temperature coefficient (NTC) thermistor. \(R_{25}\) is the nominal resistance of the thermistor at 25 C.
R-1) Measure the resistance of the thermistor, \(R_{th}\), at room temperature using your multimeter. Record the room temperature (available from the Instructor) and verify that the observed value of \(R_{th}\) is reasonably consistent with the expected value.
In order to automatically record the thermistor’s resistance, it is convenient to produce a voltage that depends on its resistance. Do this using a voltage divider as shown in Figure 2. Use a measured 10k resistor for \(R_{ref}\), and \(V_{in} = +5\mathrm{VDC}\).
Divider circuit to convert the thermistor’s resistance (\(R_{th}\)) to a measureable voltage.
R-2) Use the divider to measure the thermistor’s resistance when you hold the thermistor’s head between thumb and forefinger for a while. Estimate your hand’s temperature using the thermister conversion formula.
The voltage produced by the thermistor divider circuit is a complicated function of the temperature, so it would be convenient to directly convert the thermistor’s output into a temperature. A digital device called a microcontroller can automate this measurement and calculation. Microcontrollers are extremely versatile devices, and are handy for many tasks where complicated algorithms and nonlinear operations need to be implemented.
WARNING: To avoid zapping - and possibly destroying - your Arduino with a static discharge, it is best to ground yourself before touching your Arduino.
Plug in your Arduino board into any available USB port your computer.
The Arduino IDE should already be available on the desktop of the lap computer, but if not - or if you wish to use your own laptop - download and install it.
Start up the Arduino
program on the desktop, and configure the software to communicate with an Arduino Uno board.
Board
under the Tools
menu is chosen to be Arduino Uno, and the Port
is chosen to be the one with Arduino Uno in its name.To upload and run a program (called a “sketch”) to the Arduino, you first need to compile it, and upload it (using the button shaped like a right arrow). Try the simple Blink
example first:
File
\(\rightarrow\) Examples
\(\rightarrow\) 01.Basics
\(\rightarrow\) Blink
Blink
by clicking on Sketch
\(\rightarrow\) Verify/Compile
or on the Verify
“check mark” button.Blink
to the Arduino by clicking on Sketch
\(\rightarrow\) Upload
or on the “right arrow” Upload
button.Arduino sketches are written in a version of C++ that is described in the Arduino Language Reference. There are many, many examples, tutorials, videos, and other Arduino help and documentation available online.
Play with the code to become familiar with the programming interface, changing the code so the LED blinks in a different pattern. After modifying the code, it is usually sufficient to click Upload
to compile and upload it.
R-3) Include your Arduino code in your report and describe what pattern it makes.
R-4) Make a short (<10 second) video showing your Arduino blinking in the pattern defined by your code, and submit via Quercus along with your report.
A device’s power supply typically provides only one voltage, but it is often the case that that different components within the device require different voltages. For example, the op-amp used later in this exercise may use \(\pm15\)V, but we only want a maximum of 5 V input into the Arduino. Another common issue is that the input voltage is not known exactly a priori, but we need to supply a precise voltage to a circuit.
In this task you will use an LM7805 voltage regulator IC to generate a precise and stable voltage.
Wire up a 7805 regulator on your breadboard as follows:
Circuit for testing the LM7805 voltage regulator. Choose capacitors between 0.1 and 1 µF.
R-5) Connect the output (pin 3) of the 7805 to ground with a 1k resistor. Use your multimeter to measure (and report) the output voltage for input voltages of 5, 7, and 25V. What is the percentage difference in the the output voltage between 7 and 25V input voltages?
Except for removing the 1K resistor, do not disassemble this circuit. You will use it later.
The analog inputs of the Arduino are connected to a 10-bit analog-to-digital converter with a voltage range from 0 to 5 V.
WARNING: Applying voltages outside the range of 0 to +5 V to the Arduino analog input pins may destroy the Arduino’s Analog-to-Digital Converter (ADC).
R-6) To 1mV precision, what is the smallest voltage step size (i.e. mV/bit) of this ADC?
R-7) What are the minimum and maximum voltages that can be safely measured on an Arduino analog input pin?
The DC input impedance of the Arduino ADC is 100M, but it can temporarily be much, much lower as its internal capacitors charge and could even be below \(R_{t}\), so if the ADC is fed directly by the thermistor divider, \(V_{out}\) could sag leading to inaccurate temperature measurements. Therefore we will construct an op-amp follower to sit between the divider and the microcontroller. The follower presents a large input impedance to the divider, and a small output impedance to the microcontroller.
Wire up an op amp follower as shown in the figure below. An op amp follower is just a non-inverting amplifer (see Lab 4) with \(R_2=0\) and \(R_1=\infty\), hence a gain of \(V_{out}/V_{in}=1\). The Zener is added to provide some protection against over-voltages on the Arduino analog input pins.
Op-Amp Follower with Zener diode to limit output voltage to below 4.7 V.
As you start building more complicated circuits, breadboard organization makes them easier to build correctly and debug when things go wrong. As an example of moderate organization, here is my breadboard at the end of today’s exercise.
Example of Prof. Bailey’s breadboard for today’s exercise R-10.
To learn how to measure voltages using the Arduino, build this simple circuit feeding an Arduino Analog Input pin.
Use the File
\(\rightarrow\) Examples
\(\rightarrow\) 01.Basics
\(\rightarrow\) AnalogReadSerial
example to read the voltage from pin A0.
Tools
\(\rightarrow\) Serial Monitor
Autoscroll
box below the output screen is ticked.By changing the potentiometer, you can feed various voltages into the Arduino. By measuring the input voltage with your multimeter, and comparing it to the values reported by the Arduino, measure the conversion factor between volts and the Arduino output.
R-8) Does the measured volts/bit agree with the expected value?
Replace your potentiometer with your thermistor.
Modify an Arduino program that converts the output of the thermistor circuit into temperature and prints it out on the serial port. The basic program, arduino_thermistor.ino, is available on the course resources page.
Use Tools
\(\rightarrow\) Serial Plot
to show the temperature as a function of time, while heating up the thermistor with your hand and then removing your hand to let it cool down.
R-9) Take a photo of the plot and include it in your report, noting on the photo the times when you are holding the thermistor.
Blink
.
Although Serial Monitor and Serial Plot are very useful, it is generally better to to transmit data from the Arduino to our own computer where it can be stored and analyzed. We will (unsuprisingly) use Python for this.
Open up arduino_Serial_reader.py in your preferred python environment, e.g. Spyder, Jupyter, ….
Carefully read the instructors at the beginning of the python file. For example, you need to replace
port = '/dev/cu.usbmodem143301'
with the correct port for your Arduino, visible under the Arduino IDE Tools menu. If you have trouble identifying the correct port, you can run port_check.py to list all the operating serial ports on your computer.
pyserial
is not already installed in your python environment, you will need to install it.
pyserial
can be installed and used with any python, but it is harder for us to help you debug problems if you are not using the standard UofT undergraduate Physics Anaconda Python.Start arduino_Serial_reader.py running.
access denied
error, it is likely that the Arduino Serial Monitor or Plotter is running and controlling the port. Closing the Arduino IDE should solve the problem and allow python to access the port.While the python code is running:
R-10) Include a screen capture of the resulting plot showing the rise and fall in thermistor voltage.
This week’s exercise could be the basis for a variety of final projects, either using the thermistor, or using similar circuits with a photodiode or piezo transducer.
See you in the next lab!