ARDUINO-BASED DATA ACQUISITION INTO EXCEL, LABVIEW, AND

Download pensive. As an alternative, data can be acquired using a low-cost Arduino microcontroller.1 The Arduino has been used in physics labs where...

0 downloads 549 Views 1MB Size
Arduino-Based Data Acquisition into Excel, LabVIEW, and MATLAB Daniel Nichols

Citation: The Physics Teacher 55, 226 (2017); View online: https://doi.org/10.1119/1.4978720 View Table of Contents: http://aapt.scitation.org/toc/pte/55/4 Published by the American Association of Physics Teachers

Articles you may be interested in An Arduino-Based Magnetometer The Physics Teacher 55, 274 (2017); 10.1119/1.4981032 Connecting Time and Frequency in the RC Circuit The Physics Teacher 55, 228 (2017); 10.1119/1.4978721 The Polarization of Light and Malus’ Law Using Smartphones The Physics Teacher 55, 264 (2017); 10.1119/1.4981030 Mobile Phone Radiation and Cancer The Physics Teacher 55, 210 (2017); 10.1119/1.4978714 Two Types of Truth in the Physics Classroom The Physics Teacher 55, 218 (2017); 10.1119/1.4978717 Know Your Bulbs! The Physics Teacher 55, 231 (2017); 10.1119/1.4978722

Arduino-Based Data Acquisition into Excel, LabVIEW, and MATLAB Daniel Nichols,

D

DeVry University, Chicago, IL

ata acquisition equipment for physics can be quite expensive. 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 using 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 manually 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.

Fig. 3. View of Excel spreadsheet along with PLX-DAQ macro.

The Arduino Uno

Interfacing the Arduino to Excel

The Arduino Uno is a microcontroller with 14 digital inputs 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 computer 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 luminosFig. 1. Arduino Uno connected ity sensor, and the ADXL-335 to an LM35 temperature sentriple-axis accelerometer, all sor. 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 Excel can be done easily using a Parallax Data Acquisition tool (PLX-DAQ) software free addin for Microsoft Excel.8-11 To interface the Arduino to Excel, the Arduino would first have to be programmed with the Arduino software (IDE) shown in Fig. 2. Once the Arduino code is uploaded into the Arduino, click on the PLX-DAQ spreadsheet 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.

//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.

226

THE PHYSICS TEACHER ◆ Vol. 55, April 2017

Interfacing the Arduino to MATLAB Interfacing 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. 4. MATLAB code and plot for reading sensor connected to port A0. DOI: 10.1119/1.4978720

10. http://www.instructables.com/id/Sending-data-from-Arduino-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-andarduino-to-acquire-analog-signals-100739.html . 14. http://www.mathworks.com/hardware-support/arduinomatlab.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,” Automation Monitoring 61 (12), (Dec. 2015). 18. https://www.google.com/sheets/about/. 19. http://www.instructables.com/id/Visualize-data-from-sensorsusing-Arduino-coolte/.

Fig. 5. Front panel of LabVIEW code to acquire data from Arduino.

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 connected to and the data will be plotted.

Summary

Students

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]

gravitate

The Arduino microcontroller and some inexpensive sensors towards physics with the can be used as a cheap alternative to expensive data acquisition equipment. The most Computerized 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 analysis program of your choice. The software used in this article was arduino-1.6.4, Excel 2013, MATLAB R2015b, and LabVIEW2013, and run on Windows 7 Enterprise. To ensure compatibility on your computer, check the system requirements for these add-ins.

cavendish Balance

TEL-Atomic Incorporated

Providing you with tools to teach advanced Physics  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

computerized cavendish

balance

References

1. 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. For product details >> www.telatomic.com 51, 156 (March 2013). 800.622.2866 [email protected] 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 . Tel-Atomic Cavendish AD.indd 1 12/7/2010 10:56:49 PM 9. https://www.parallax.com/downloads/plx-daq .

THE PHYSICS TEACHER ◆ Vol. 55, April 2017

227