MathWorks - Mobile View
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 다운로드
MathWorks
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 다운로드
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃

비디오 및 웨비나

  • MathWorks
  • 비디오
  • 비디오 홈
  • 검색
  • 비디오 홈
  • 검색
  • 영업 상담
  • 평가판 신청
  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

  • 영업 상담
  • 평가판 신청

제품 소개

  • MATLAB
  • Simulink
  • 학생용 소프트웨어
  • 하드웨어 지원
  • File Exchange

다운로드 및 구매

  • 다운로드
  • 평가판 신청
  • 영업 상담
  • 가격 및 라이선스
  • MathWorks 스토어

사용 방법

  • 문서
  • 튜토리얼
  • 예제
  • 비디오 및 웨비나
  • 교육

지원

  • 설치 도움말
  • 사용자 커뮤니티
  • 컨설팅
  • 라이선스 센터
  • 지원 문의

회사 정보

  • 채용
  • 뉴스 룸
  • 사회적 미션
  • 영업 상담
  • 회사 정보

MathWorks

Accelerating the pace of engineering and science

MathWorks는 엔지니어와 과학자들을 위한 테크니컬 컴퓨팅 소프트웨어 분야의 선도적인 개발업체입니다.

활용 분야 …

  • Select a Web Site United States
  • 특허
  • 등록 상표
  • 정보 취급 방침
  • 불법 복제 방지
  • 매스웍스코리아 유한회사
  • 주소: 서울시 강남구 삼성동 테헤란로 521 파르나스타워 14층
  • 전화번호: 02-6006-5100
  • 대표자 : 이종민
  • 사업자 등록번호 : 120-86-60062

© 1994-2021 The MathWorks, Inc.

  • Naver
  • Facebook
  • Twitter
  • YouTube
  • LinkedIn
  • RSS

대화에 참여하기