PHY 405: Electronics Lab Lab # 3 Lab # 3: Analog meets digital In this lab you will learn how to use a microcontroller to build a thermometer that logs the temperature to a computer. You will also learn how to communicate with the oscilloscope through a serial port, using Python programs. Background preparation • Thermistors: Wikipedia. • Serial communication: Wikipedia. • Analog to digital converters (ADC): AOE. Task 1: Measuring a thermistor’s output In this task, you will build a circuit to measure the resistance of a thermistor, a resistor whose resistance depends on temperature. The thermistor1 is an NTC type (negative temperature coefficient, i.e., its resistance decreases with temperature). Its nominal resistance at 25 C is R25 = 10 kΩ. 6 Temperature, T−273.15 [C] 20 40 60 0 80 5 R/R25 4 3 2 1 0 260 280 300 320 Temperature, T [K] 340 360 Figure 1: Resistance versus temperature for a negative temperature coefficient (NTC) thermistor. The quantity R25 is the nominal resistance of the thermistor at 25 C. 1 The thermistor you will use is a Vishay # NTCLE100E3103HB0. 1 PHY 405: Electronics Lab Lab # 3 The thermistor’s datasheet provides the following formula for converting its resistance to temperature (in Kelvin): 2 3 R 1 R R + D1 ln . = A1 + B1 ln + C1 ln T (R) R25 R25 R25 (1) The constants for this thermistor type (in units of K −1 ) are A1 = 3.354016 × 10−3 , B1 = 2.884193 × 10−4 , C1 = 4.118032 × 10−6 , D1 = 1.786790 × 10−7 . a) Measure the resistance of the thermistor, Rth , using a multimeter. Record the room temperature, Troom , and verify that Rth is consistent with the curve shown in Figure 1. b) In order to automatically record the thermistor’s resistance, it is convenient to produce a voltage that depends on its resistance. You will do this using a voltage divider. Wire up a resistive divider circuit as shown in Figure 2. Use a value of Rref between 1-5 k, and Vin of +5 V. Measure and record the value of Rref before you put it in. Measure the output voltage of the divider when you touch the thermistor’s head with your fingers. Estimate your hand’s temperature using the calibration curve in Figure 1, and the calculated division ratio of the divider. Vin Vout Rth Rref Figure 2: Divider circuit to convert the thermistor’s resistance to a measurable voltage. (30 mins) Task 2: Converting the thermistor’s output to a temperature As you observed in the previous task, the voltage produced by the thermistor divider circuit is a complicated function of the temperature. Wouldn’t it be convenient to somehow directly convert the thermistor’s output into a temperature? In this task, you will use a digital device called a microcontroller (uC) to automate this calculation. Microcontrollers are extremely versatile devices, and are handy for many tasks where complicated algorithms and nonlinear operations need to be implemented. 2 PHY 405: Electronics Lab Lab # 3 a) Plug in your uC board into any available USB port on the computer. (You may disconnect the “LabDAQ” instrument if necessary.) Start up the Arduino program on the desktop, and configure the software to communicate with an Uno board. Make sure that the Board is chosen to be “Arduino/Genuino Uno”, and the Port is chosen correctly for the uC that you plugged in. To upload a program (called a “sketch”) to the uC board, you will need to first compile it (indicated by the Verify button, shaped like a check mark), and upload it (using the button shaped like a right arrow). Try the simple Blink example first, and modify the code so that you get familiar with the programming interface. Next, complete the AnalogReadSerial example,2 using a potentiometer to generate a variable voltage. Warning: Never send in voltages outside the range of 0 to +5 V into the analog input pins of the uC. If you significantly exceed this range, you may destroy the microcontroller’s ADC. Feel free to try out any of the other examples. b) Connect the output of the thermistor’s divider circuit to one of the uC’s analog inputs. Write a uC program to convert the output of the thermistor circuit into temperature, and print out the temperature measurements on the serial port. A basic program to get you started (arduino thermistor.pde) is available on the course webpage. Use the uC and the thermistor to measure the root-mean-squared (rms) temperature fluctuations in the room over a span of one hour, and report this value. Estimate the contribution of the uC’s internal circuitry to the observed fluctuations, and figure out the true extent of the room’s temperature variations. (Hint: what happens if there is just a resistor, rather than a thermistor, connected to the uC’s input?) In your report, describe how you estimated the true value of the rms temperature fluctuations. (1 hr 20 mins) Task 3: Communicating with the oscilloscope The front-end of the TDS 210 oscilloscope is also just a specialized ADC. In this task, you will use a Python program to communicate with the scope, and read out waveforms from it. This allows you to download data from the scope for further analysis. a) Connect the scope to the computer through a USB (Universal Serial Bus) port. You may have to plug the scope’s USB cord into one of the front panel USB sockets on the desktop computer. Watch for the serial port number when the USB device driver installs (the serial port address will be something like “COM4”). Download the program called scope serial.py from the course webpage, and open it in a Notepad window. Edit the address listed in the program to match the correct COM 2 The Blink and AnalogReadSerial examples can be found under File 3 → Examples. PHY 405: Electronics Lab Lab # 3 port address for the scope, and save the program on the desktop. Run the program using python.exe. If you have configured the COM port address correctly (and turned on the scope!), you should see a window listing the scope’s serial number. Read through scope serial.py and try to understand what the various functions do.3 Feel free to modify and play with the Python program. b) Set up the function generator to output a 1.213 kHz triangle wave, and connect its output to the scope. Using scope serial.py, acquire the waveform from the scope and save it into a text file for further analysis. In your report, plot the waveform and its power spectrum. A basic program to calculate the power spectrum of a waveform is available on the course webpage. (40 mins) 3 The TDS 210 programming manual posted on the course webpage might help you make sense of the commands. 4