Skip to content
MathWorks - Mobile View
  • MathWorks アカウントへのサインインMathWorks アカウントへのサインイン
  • Access your MathWorks Account
    • マイ アカウント
    • コミュニティのプロファイル
    • ライセンスを関連付ける
    • サインアウト
  • 製品
  • ソリューション
  • アカデミア
  • サポート
  • コミュニティ
  • イベント
  • MATLAB を入手する
MathWorks
  • 製品
  • ソリューション
  • アカデミア
  • サポート
  • コミュニティ
  • イベント
  • MATLAB を入手する
  • MathWorks アカウントへのサインインMathWorks アカウントへのサインイン
  • Access your MathWorks Account
    • マイ アカウント
    • コミュニティのプロファイル
    • ライセンスを関連付ける
    • サインアウト

ビデオ・Webセミナー

  • MathWorks
  • ビデオ
  • ビデオ ホーム
  • 検索
  • ビデオ ホーム
  • 検索
  • 営業へのお問い合わせ
  • 評価版
3:45 Video length is 3:45.
  • Description
  • Full Transcript
  • Code and Resources

Plotting Live Data of a Temperature Sensor using Arduino and MATLAB

MATLAB® can be used to quickly analyze and visualize data collected from sensors connected to Arduino®. Collect and plot live data from a temperature sensor and then analyze the data using some of the built-in MATLAB functions.

Download the code used in this video.

I've created a script called Temperature Logging and I've broken it down into sections. To run a section of code and advance to the next one, you can use the run and advance button inside MATLAB Editor. I have a snapshot from the data sheet of the DNP 36 sensor. And we can see the temperature is directly proportional to the voltage output that it gives. This is the equation. When I run the section, we can see what the temperature reading is in this room, both in Celsius and Fahrenheit.

I'm using the same equation to collect data for a specified period of time using tic and toc. We can see that it takes a long time to collect this data. This is because MATLAB sends a serial command to the device and receives a response every time to acquire a new data point. This is causing a bottleneck, which determines the fastest speed at which we can acquire data. We can also see that the data is pretty choppy.

First, let's calculate the frequency at which MATLAB can collect the data and then come to see why the data is choppy. So the frequency is about 72 hertz. The data is choppy because the Arduino we are using is an 8-bit device and it only reads values between 0 and 1023 on its analog pins. And remember, the voltage range was 0 to 5. So when we use these values, we can see that it corresponds to a reading of about 0.5 degrees centigrade and 1 Fahrenheit. That explains a little bit on why the data is so choppy, because even a small change in the voltage value means that there is a significant change in temperature.

Oftentimes, it is helpful to observe the data values as they are being collected. And during this, I am touching the temperature sensor with my finger to see how the measured value changes and if I can influence the temperature. So the function being used is animated line, which makes it easy to stream new data to a plot. The other useful feature of this function is that the data is automatically stored in the plot and we don't have to log it. I have set up the script so when I push the button, it stops collecting data.

Let us take a look at the data that we collected. This data definitely needs some post-processing. The high-frequency noise in the temperature signal can be removed by applying a moving average filter. From the datasheet, we know that the temperature sensor has a tolerance of about 2 degrees centigrade at room temperature. So using this information, I have calculated the largest and smallest possible value and plotted both the collected and the process data.

The continuous line here is the filtered data. And the temperature sensor tolerance is represented using the dotted lines in this figure. Now that we have done all the analysis and can see the data, we might want to save the data that we collected to a file. One way to do this is to store the data in a table and then write the table itself to a file. You can see that the file has all the necessary information and the collected data itself. Thanks, everyone.

Download Code and Files

Download Example Code

Related Products

  • MATLAB

3 Ways to Speed Up Model Predictive Controllers

Read white paper

A Practical Guide to Deep Learning: From Data to Deployment

Read ebook

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper

Deep Learning and Traditional Machine Learning: Choosing the Right Approach

Read ebook

Hardware-in-the-Loop Testing for Power Electronics Control Design

Read white paper

Predictive Maintenance with MATLAB

Read ebook

Electric Vehicle Modeling and Simulation - Architecture to Deployment : Webinar Series

Register for Free

How much do you know about power conversion control?

Start quiz

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

3:38
Using MATLAB and Arduino to Acquire Analog Signals

Related Videos:

4:21
Using MATLAB and Arduino for Motor Control
33:09
Using Arduino with MATLAB and Simulink
5:42
Using MATLAB and Raspberry Pi with an I2C Sensor
2:59
How to Use Basic Plotting Functions

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

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

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

  • 営業へのお問い合わせ
  • 評価版

MathWorks

Accelerating the pace of engineering and science

MathWorksはエンジニアや研究者向け数値解析ソフトウェアのリーディングカンパニーです。

ディスカバー…

製品を見る

  • MATLAB
  • Simulink
  • 学生向けソフトウェア
  • ハードウェア サポート
  • File Exchange

製品評価版の入手または製品の購入

  • ダウンロード
  • 評価版ソフトウェア
  • 営業へのお問い合わせ
  • 価格とライセンス
  • MathWorksストア

使い方を学ぶ

  • ドキュメンテーション
  • チュートリアル
  • 例
  • ビデオ・Webセミナー
  • トレーニング

サポートを受ける

  • インストールのヘルプ
  • MATLAB Answers
  • 技術コンサルティング
  • ライセンスセンター
  • サポートへのお問い合わせ

MathWorks について

  • 採用情報
  • ニュースルーム
  • 社会貢献
  • ユーザー事例
  • MathWorks について
  • Select a Web Site United States
  • トラストセンター
  • 商標
  • プライバシー ポリシー
  • 違法コピー防止
  • アプリケーション ステータス

© 1994-2022 The MathWorks, Inc.

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

MATLAB を語ろう