MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
MathWorks
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out

Videos and Webinars

  • MathWorks
  • Videos
  • Videos Home
  • Search
  • Videos Home
  • Search
  • Contact sales
  • Trial software
  Register to watch video
  • Description
  • Full Transcript
  • Related Resources

Using MATLAB and Arduino to Acquire Analog Signals

Madhu Govindarajan, MathWorks

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.

I am using an Arduino Due, TMP 36 temperature sensor, and a USB-Micro B cable for this demo. To measure the temperature using MATLAB, connect your TMP 36 sensor. Pin 1 to 5 volt on the Due. Pin 3 to GND. And Pin 2 to A7 on the Due. Remember, the USB cable must be connected to the programming port on the Due.

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.

I'm going to click on Getting Started and find out how I can connect to Arduino board from MATLAB. I'm going to copy the code snippet that is given here and paste it on MATLAB command window to establish a connection with the first available Arduino board that is connected to this PC.

Our next task is to measure the temperature sensor's analog signal using MATLAB. Search Arduino analog. The first suggestion provided by MATLAB is lead voltage function, which can read analog voltage from Arduino boards. Let us go to MATLAB command window and see if we can measure the analog signal using this function.

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.

Related Products

  • MATLAB

Learn More

Download MATLAB Support Package for Arduino

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

4:21
Using MATLAB and Arduino for Motor Control

Related Videos:

33:09
Using Arduino with MATLAB and Simulink
10:36
Videos, Images, Signals? Stream Processing in MATLAB with...
7:15
Arduino and MATLAB: Reading Inputs and Writing Outputs
2:04
Install the MATLAB and Simulink Support Packages for Arduino

View more related videos

MathWorks - Domain Selector

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

Select web site

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érica Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Contact sales
  • Trial software

Explore Products

  • MATLAB
  • Simulink
  • Student Software
  • Hardware Support
  • File Exchange

Try or Buy

  • Downloads
  • Trial Software
  • Contact Sales
  • Pricing and Licensing
  • How to Buy

Learn to Use

  • Documentation
  • Tutorials
  • Examples
  • Videos and Webinars
  • Training

Get Support

  • Installation Help
  • Answers
  • Consulting
  • License Center
  • Contact Support

About MathWorks

  • Careers
  • Newsroom
  • Social Mission
  • Contact Sales
  • About MathWorks

MathWorks

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Discover…

  • Select a Web Site United States
  • Patents
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status

© 1994-2021 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Join the conversation

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic.  By continuing to use this website, you consent to our use of cookies.  Please see our Privacy Policy to learn more about cookies and how to change your settings.