Project tutorial

Arduino Real-Time Plotting with MATLAB

Arduino and Python-based project that will help us read the sensor values and plot it on MATLAB.

  • 6,526 views
  • 1 comment
  • 15 respects

Components and supplies

Apps and online services

About this project

Introduction:

Analytics is one of the best tools which help you gain information about what is happening, and help you to see the trends in the data. Companies like Facebook, Google, Uber, Amazon, and many others use the help of analytics to perform certain tasks, such as ads.

This project will help you do analysis on your sensor data in real-time. In this project, we are going to take sensor values and send it on MATLAB script running on our laptop serially and will plot those serial values in real time.

MATLAB has been used for multiple purpose and in this tutorial we are going to use it for real time data plotting.

We will read the analog values of potentiometer and our favorite development board Arduino will help us do that and the value will be sent to MATLAB serially.

Check out how to do the same task with Python:

Set Up MATLAB Arduino Hardware Support:

MATLAB being the matrix lab and the tool for mathematical processing have 100s of tools, some of them comes pre installed and you will have to install some. So our first task will be to install the MATLAB Arduino support and you can do that by following the method discussed below,

  • First, start MATLAB and click the Add-Ons drop down menu. In the drop-down menu click Get Hardware Support Packages. It will start the package installer window.
  • Select Install from internet and then Next.
  • In the next window you will see all the available packages for MATLAB and Simulink. Select the Arduino package, then check all the packages displayed and click Next to continue installation.
  • Next, the installer will ask you to log in to your Math Works account. If you don’t have an account, you can create one during installation. Accept the license agreement on the next screen and continue to download the packages. Now you have to wait for MATLAB to download and install all the required packages.

Package Testing:

Once the packages are installed, connect your Arduino board to your PC and type the following command in MATLAB command window,

>> a = arduino()

if you have more than one Arduino connected to your PC, you have to specify the board type you will be communicating with:

>> a = arduino(‘com3’, ‘uno’)

MATLAB will then attempt to communicate with your board. If successful, MATLAB will display the properties of the Arduino board connected to your PC.

Make Circuit Diagram and Write MATLAB Script:

Then all you have to do is to make circuit diagram which is quite simple and is attached and then write MATLAB code (attached) and run the program.

Video:

Don't Forget to Subscribe and Like Our Facebook Page:

Facebook

YouTube

Code

Matlab CodeMATLAB
clc

global a;

if ~isempty(instafind)
fclose(instrfind);
delete(instrfind);
end

% The above if-condition will help you find the COM port.

a= arduino();
%make "a" object of arduino

interv = 200;
%defining time

init_time = 1;
%initial time

x=0;

while (init_time<interv)
  b=readVoltage(a,'A0');
%reading voltages from pin A0 , reads voltages not adc value ,
%voltages = (ADC*5)/1024
  x=[x,b];
  plot(x)
  grid ON
  init_time=init_time+1;
  drawnow
end

%the above loop will run for 200 values, if you want to run it for more time change the interv value  
  

Schematics

Circuit
Fvahratjr0yvjas large crygsjbump

Comments

Similar projects you might like

Test DHT22 Sensors with Arduino and MATLAB

Project tutorial by dancili

  • 5,201 views
  • 2 comments
  • 22 respects

Measure and Analyze Tide Levels with ThingSpeak and MATLAB

Project tutorial by Team MATLAB IoT

  • 10,458 views
  • 1 comment
  • 31 respects

Robotic Arm: Arduino + Matlab

Project showcase by Konrad Witt

  • 12,957 views
  • 10 comments
  • 32 respects

2€ OLED I2C Analog Pin Dynamic Plotting

Project showcase by javier muñoz sáez

  • 6,486 views
  • 0 comments
  • 14 respects

Arduino Bluetooth Robot for Android Device

Project showcase by aip06

  • 2,577 views
  • 1 comment
  • 10 respects
Add projectSign up / Login