使用Matlab和Arduino获取模拟信号
This hands-on tutorial shows how to use MATLAB®and Arduino®boards to acquire temperature data from a TMP36 sensor. You can acquire and analyze sensor data with MATLAB Support Package for Arduino.
In this demo, we are going to see how to measure temperature using an Arduino board and MATLAB. The same technique can also be used to measure other analog signals. For this, I have MATLAB and MATLAB Support Package for Arduino pre-installed. If you do not have the support package installed, then you can go to Add-ons tab and click on Get Hardware Support Package to download and install the support package.
我正在为此演示使用Arduino育条,TMP 36温度传感器和USB-Micro B电缆。要使用MATLAB测量温度,请连接TMP 36传感器。引脚1至5伏。引脚3至GND。以及应付款的引脚2至A7。请记住,USB电缆必须连接到欠款上的编程端口。
To get started with MATLAB Support Package for Arduino, let us go to the documentation home using one of the many ways. Type doc on MATLAB command window, then scroll down on the page that just opened up inside the hub browser. In the bottom-right corner, a list of all the installed support packages and links to their homepage is available.
我将点击入门,找出如何从MATLAB连接到Arduino Board。我将复制此处给出的代码段,并将其粘贴到Matlab命令窗口上,以建立与该PC连接的第一个可用Arduino板的连接。
我们的下一个任务是使用MATLAB测量温度传感器的模拟信号。搜索Arduino类似物。MATLAB提供的第一个建议是铅电压函数,它可以读取Arduino板的模拟电压。让我们转到MATLAB命令窗口,看看是否可以使用此功能测量模拟信号。
I repeated the function a few times to make sure that I'm reading the stabilized voltage from the sensor. Now, the next task is to convert this value of voltage to temperature. For this, I'm going to explain when you can use a function in MATLAB. Functions must be used to perform a repetitive task such as this one for different input values. I have a function here called voltToFa, which will convert the voltage values of the temperature sensor to Fahrenheit.
The first line in this function converts the voltage to Celsius using the formula given in the manual for the sensor. The second line converts this Celsius value using the standard formula to a Fahrenheit value. A script, on the other hand, can be used to perform a repetitive task. However, it cannot take in input values.
I have a script here called temp-from-sensor that uses read voltage function that we just learned about and the function voltToFa to measure the voltage from the sensor and convert it to temperature. To show the effectiveness of the temperature sensor, I've connected a webcam to monitor the thermostat in my office. I obtained a stream of images from the webcam, and I am displaying it along with the temperature's value. For this, I'm using the Preview function available in MATLAB Support Package for webcams.
With that, we have seen how to measure temperature or any analog signal using MATLAB and an Arduino board.
Featured Product
MATLAB
Up Next:
有关的影片:
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- 丹麦(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- Italia(意大利语)
- Luxembourg(English)
- 荷兰(English)
- 挪威(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia(English)
- India(English)
- New Zealand(English)
- 中国
- 日本Japanese(日本語)
- 한국Korean(한국어)