header ads

Arduino MATLAB Interface Made Easy – How to Interface Arduino with MALTAB?

In this venture, I'll demonstrate to you how the Arduino MATLAB Interface functions and every one of the means associated with interfacing Arduino with MATLAB.

Arduino is one of the most loved prototyping stage among producers and specialists. MATLAB, then again, is an expert numerical registering apparatus utilized by designers and researchers. Interfacing Arduino with MATLAB makes things intriguing as one is gone for a section and specialist dimension of clients while the other is a perplexing device utilized by experts.

How Arduino MATLAB Interface Works?

We regularly use Arduino IDE to compose and transfer projects (or Sketches) to Arduino. This is fine for customary use yet in the event that you need to plot the information got from sensors, at that point the programming turns into a tedious assignment.

MATLAB addresses a few such issues in Arduino Programming with the assistance of two kinds of procedures:

Perusing, composing and examining information from Sensors

Creating Algorithms that keep running as independent program on Arduino

So as to accomplish this, we need an additional bundle for MATLAB called MATLAB Support Package for Arduino. This is authoritatively discharged by MATLAB and is accessible for nothing in their site (you need a record to download this bundle).

Installing MATLAB Support Package for Arduino

Presently we'll perceive how to introduce the MATLAB Support bundle for Arduino. To start with, begin the MATLAB Application and in the RESOURCES Tab, go to Add-ons and select Get Hardware Support Packages choice.

Arduino MATLAB Interface Image 1 


In the wake of instating the extra, you will at that point inspire an alternatives of how to introduce the bundle for example from the web or from a document as of now that is now downloaded. I've introduced from the web.

You will at that point get a rundown of all the accessible Support Packages. Select Arduino and check the MATLAB Support Package. There are Arduino Support Packages for Simulink as well but we will leave it for later.
Arduino MATLAB Interface Image 2

Now, the MATLAB Application will ask you to login to you MathWorks Account. If you have an account, use those credentials and login or you can create an account during installation. Next, accept the license terms and continue to download the package.
MATLAB will now download and install the selected packages. Sit back and relax until it is done. 

Interfacing Arduino with MATLAB and Testing the Support Package

After installing the Arduino Package for MATLAB, we will now see how to interface Arduino and MATLAB. Connect the Arduino board to the computer that is running MATLAB and open MATLAB Application.
In the command window, type the following and hit enter.

a = arduino ()
This step will create a connection between MATLAB and Arduino and returns with the properties of the Arduino Board like COM Port, Name, etc. as shown in the screenshot below.
Arduino MATLAB Interface Image 3
If more than one Arduino board is connected to the computer and if you want to communicate with a specific board, use the following command.

a = arduino (‘com8’, ’Mega2560’)
NOTE: You have to clear the variable ‘a’ using the command ‘clear a’.

Programming Arduino using MATLAB

We will presently perceive how to program the Arduino Board utilizing MATLAB Programming. For this, I will utilize the Arduino Mega Board. It has an on-board LED associated with Digital Pin 13.

I'll compose a MATLAB Program so as to flicker this LED for multiple times with a postponement of 1 second. Then again, you can associate an outside LED with a present restricting resistor to the Digital Pin 13 and the accompanying picture demonstrates the circuit chart for this association.
Arduino MATLAB Interface Image 4
In the file tab, go to New and select Script option. A blank editor will be opened. Paste the code mentioned in the following section and save the file. It will be save as a .m file, which is the extension for MATLAB Programs.
NOTEChange the COM Port and Arduino Board as indicated by your necessities in the code.

In the wake of sparing the record, click on Run alternative. The MATLAB program will associate with the Arduino Board and will play out the ideal choice.

An imperative point to be noted is that the program won't be transferred to Arduino and thus on the off chance that you reset or restart the Arduino Board, the program will be lost and you have to play out the above advances indeed.

There is another approach to program Arduino Board through MATLAB, yet we will see that later.

CODE


Summary of Arduino MATLAB Interface

  • Download and Install the Arduino Hardware Support Package for MATLAB. 
  • Interface the Arduino board to the PC running MATLAB and check if the Arduino can be imparted through MATLAB. 
  • Make a straightforward circuit for flickering a LED associated with one of the Digital Pins of Arduino. 
  • Compose a MATLAB program for flickering the LED and spare it as a .m document. 
  • Run the MATLAB Program and the LED associated with Arduino should begin squinting according to the program.

Applications of Arduino MATLAB Interface

  • By interfacing Arduino with MATLAB, we can get Sensor Data from Arduino and begin plotting different diagrams. 
  • We can make GUI (Graphical User Interface) for controlling our Arduino with the assistance of MATLAB. 
  • A wide scope of activities identified with picture preparing and flag handling can be actualized utilizing Arduino and MATLAB. 
  • A portion of the tasks can be Color Detection, Object Tracking, Face Detection, and so forth.


Post a Comment

2 Comments