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 (
The thermistor’s datasheet provides the following formula for converting its resistance to temperature in Kelvin:
The constants for this thermistor type (in units of
Resistance versus temperature for a negative temperature coefficient (NTC) thermistor.
R-1) Measure the resistance of the thermistor,
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
Divider circuit to convert the thermistor’s resistance (
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
Examples
01.Basics
Blink
Blink
by clicking on Sketch
Verify/Compile
or on the Verify
“check mark” button.Blink
to the Arduino by clicking on Sketch
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
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
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
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
Examples
01.Basics
AnalogReadSerial
example to read the voltage from pin A0.
Tools
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
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!