Upload
lamtruc
View
238
Download
0
Embed Size (px)
Citation preview
Arduino-Based Data Acquisition into Excel, LabVIEW, and MATLABDaniel Nichols
Citation: The Physics Teacher 55, 226 (2017);View online: https://doi.org/10.1119/1.4978720View Table of Contents: http://aapt.scitation.org/toc/pte/55/4Published by the American Association of Physics Teachers
Articles you may be interested in An Arduino-Based MagnetometerThe Physics Teacher 55, 274 (2017); 10.1119/1.4981032
Connecting Time and Frequency in the RC CircuitThe Physics Teacher 55, 228 (2017); 10.1119/1.4978721
The Polarization of Light and Malus’ Law Using SmartphonesThe Physics Teacher 55, 264 (2017); 10.1119/1.4981030
Mobile Phone Radiation and CancerThe Physics Teacher 55, 210 (2017); 10.1119/1.4978714
Two Types of Truth in the Physics ClassroomThe Physics Teacher 55, 218 (2017); 10.1119/1.4978717
Know Your Bulbs!The Physics Teacher 55, 231 (2017); 10.1119/1.4978722
226 THE PHYSICS TEACHER ◆ Vol. 55, April 2017 DOI: 10.1119/1.4978720
Arduino-Based Data Acquisition into Excel, LabVIEW, and MATLABDaniel Nichols, DeVry University, Chicago, IL
Data acquisition equipment for physics can be quite ex-pensive. As an alternative, data can be acquired using a low-cost Arduino microcontroller.1 The Arduino
has been used in physics labs where the data are acquired us-ing the Arduino software.2-4 The Arduino software, however, does not contain a suite of tools for data fitting and analysis. The data are typically gathered first and then imported manu-ally into an analysis program. There is a way, however, that allows data gathered by the Arduino to be imported in real time into a data analysis package. Illustrated in this article are add-ins for Excel, MATLAB, and LabVIEW that import data directly from the Arduino and allow for real-time plotting and analysis.
The Arduino Uno The Arduino Uno is a microcontroller with 14 digital in-
puts and six analog inputs with 10-bit resolution.5 It can be purchased for as little as $6 on eBay, programmed in C, and can be interfaced to a com-puter through USB, and the software is free.6 There exists a lot of inexpensive sensors the Arduino can interface to such as the LM35 for temperature sensor, the TSL2561 luminos-ity sensor, and the ADXL-335 triple-axis accelerometer, all under $15.7 As an example of
this, an LM35 temperature sensor, which outputs 10 mV/oC is monitored with an Arduino UNO, shown in Fig. 1.
Interfacing the Arduino to ExcelInterfacing the Arduino to Excel can be done easily using a
Parallax Data Acquisition tool (PLX-DAQ) software free add-in for Microsoft Excel.8-11 To interface the Arduino to Excel, the Arduino would first have to be programmed with the Ar-duino software (IDE) shown in Fig. 2. Once the Arduino code is uploaded into the Arduino, click on the PLX-DAQ spread-sheet icon. Choose the port the Arduino is connected to, check the Download Data box, and then click Connect. A graph can be added to see real-time plotting, as shown in Fig. 3.
Interfacing the Arduino to MATLABInterfacing the Arduino to MATLAB can be done easily
using a MATLAB free support package for the Arduino.12-14 There is no need to program the Arduino with the Arduino software; the support package takes care of that. MATLAB code for reading a sensor connected to the Arduino’s port A0, as well as a real-time plot, is shown in Fig. 4.
Fig. 1. Arduino Uno connected to an LM35 temperature sen-sor.
//Arduino Code to send Data to Excel
void setup() {
Serial.begin(9600); // the bigger number the better
Serial.println(“CLEARDATA”); //clears up any data left
from previous projects
Serial.println(“LABEL,Clock,Time,Data”);
//Always write LABEL, so excel knows the next things
will be the names of the columns (instead of Acolumn
you could write Time for instance)
Serial.println(“RESETTIMER”); //resets timer to 0
}
void loop() {
Serial.print(“DATA,TIME,TIMER,”);
//Writes the time in the first column A, the elapsed
time in column B, and the data in C.
Serial.print(analogRead(A0));//Read channel A0
Serial.println(“”); //be sure to add println to the
last command so it knows to go into the next row on
the second run
delay(100); //Add a 100mS delay
}
Fig. 2. Arduino code for reading sensor connected to port A0.
Fig. 3. View of Excel spreadsheet along with PLX-DAQ macro.
Fig. 4. MATLAB code and plot for reading sensor connected to port A0.
THE PHYSICS TEACHER ◆ Vol. 55, April 2017 227
10. http://www.instructables.com/id/Sending-data-from-Ardui-no-to-Excel-and-plotting-it/.
11. http://nutsvolts.texterity.com/nutsvolts/201506/?folio=34&pg=34#pg34 .
12. https://www.youtube.com/watch?v=Tm3g1bZi7To .13. https://www.mathworks.com/videos/using-matlab-and-
arduino-to-acquire-analog-signals-100739.html .14. http://www.mathworks.com/hardware-support/arduino-
matlab.html .15. http://sine.ni.com/nips/cds/view/p/lang/en/nid/212478 .16. Marco Schwartz and Oliver Manickum, Programming Arduino
with LabVIEW (Packt Publishing), ISBN: 978-1-84969-822-1.17. M. Jaskuła, M. Łazoryszczak, S. Peryt, “Fast MEMS application
prototyping using Arduino/LabView pair measurement,” Auto-mation Monitoring 61 (12), (Dec. 2015).
18. https://www.google.com/sheets/about/.19. http://www.instructables.com/id/Visualize-data-from-sensors-
using-Arduino-coolte/.
Daniel Nichols is EIS faculty member at DeVry University in Chicago. His hobby is designing and building equipment to measure and control systems. [email protected]
Interfacing the Arduino to LabVIEW
Interfacing the Arduino to LabVIEW can be done using the LINX by LabVIEW Makerhub.15-17 This is a free interface software to LabVIEW that easily allows LabVIEW to command and acquire data from the Arduino. As with MATLAB, there is no need to program the Arduino with the Arduino software; the support package takes care of that. Simply run the program in Fig. 5 and choose the correct com port the Arduino is con-nected to and the data will be plotted.
SummaryThe Arduino microcontroller and some inexpensive sensors
can be used as a cheap alternative to expensive data acquisi-tion equipment. The most expensive component used in this article is the data analysis software. An alternative to these, free spreadsheets such as Google Sheets18 can perform the analysis. There are also free serial port terminal applications, such as CoolTerm,19 which would allow data from the Arduino to be saved into a file. This data can then be imported into the analy-sis program of your choice.
The software used in this article was arduino-1.6.4, Excel 2013, MATLAB R2015b, and LabVIEW2013, and run on Win-dows 7 Enterprise. To ensure compatibility on your computer, check the system requirements for these add-ins.
References1. https://www.arduino.cc/. 2. Calin Galeriu, Cheryl Letson, and Geoffrey Esper, “An Arduino
investigation of the RC circuit,” Phys. Teach. 53, 285 (May 2015).3. Calin Galeriu, Scott Edwards, and Geoffrey Esper, “An Arduino
investigation of simple harmonic motion,” Phys. Teach. 52, 157 (March 2014).
4. Calin Galeriu, “An Arduino-controlled photogate,” Phys. Teach. 51, 156 (March 2013).
5. https://www.arduino.cc/en/Main/ArduinoBoardUno . 6. www.arduino.cc/en/Main/Software .7. https://www.adafruit.com .8. https://www.youtube.com/watch?v=xzC4SDd6sJ0 .9. https://www.parallax.com/downloads/plx-daq .
Fig. 5. Front panel of LabVIEW code to acquire data from Arduino.
Short oscillation periods of 2-4 minutes
Complete experimental results in a single lab period
No more optical lever jitters due to revolutionary sensor design
24 bit resolution
Students gravitate towards physics with the Computerized cavendish Balance
TEL-AtomicI n c o r p o r a t e d
For product details >> www.telatomic.com800.622.2866 [email protected]
Providing you with tools to teach advanced Physics
balancecomputerized cavendish
Tel-Atomic Cavendish AD.indd 1 12/7/2010 10:56:49 PM