Site icon High Voltages

Arduino Real-Time Plotting with MATLAB

Arduino Realtime graph plot using Matlab

Arduino Realtime graph plot using Matlab


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. Arduino Real-Time Plotting with MatLab project will help you to analyze the data. This project will help you connect arduino and matlab.

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 array starts from 1.
Arduino Real-Time Plotting with MATLAB
Matlab array starts from 1

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

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.

Arduino is our favorite board.
Arduino Real-Time Plotting with MATLAB
Arduino is our favorite board.

Check out how to do the same task with Python

Arduino plot graph using 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,

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.

Circuit diagram. Arduino with potentiometer.
Circuit diagram. Arduino with a potentiometer.


global a;

if ~isempty(instafind)

% 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


while (init_time<interv)
%reading voltages from pin A0 , reads voltages not adc value ,
%voltages = (ADC*5)/1024
  grid ON

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


Arduino Realtime graph plot using Matlab

Don’t Forget to Subscribe and Like us:

if you need any help in this project you can contact us.

Please Subscribe us on youtube:



Exit mobile version