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.
Originally posted at https://highvoltages.co/project/arduino/arduino-real-time-plotting-with-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 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:
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.
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.
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.
Don't Forget to Subscribe and Like Our Facebook Page:
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