Arduino board has to be the most basic development board that most people prefer for projects. It can be easily programmed and are relatively inexpensive too. But MATLAB is a more complex programming language and computing tool. Therefore the interfacing of Arduino with MATLAB is quite interesting on the basis of complexity. This project focuses on the steps involved in interfacing Arduino with MATLAB in a simplified manner
How this Interface works:
Normally a software by the name of Arduino IDE is used which uses Java for coding. It is pretty easy to use but for plotting data but for data obtained from sensors it gets a bit complex and time-consuming. MATLAB helps to create an easier interface by not only analyzing and processing data from sensors easily but also developing algorithms which run as standalone programs on Arduino.
But before you start you will require a MATLAB Support Package for Arduino. You can get it absolutely free from the official website once you have an account. Next, let us see how to install the MATLAB Support package for Arduino.
Installing Support Package for Arduino:
First, you will have to start the MATLAB Application. In the “Resources” tab click on “Add-ons”. From the drop-down click on “Get Hardware Support Packages”. Once you initialize the add-on you will get options to install the package from the internet or a file already downloaded. Here we are using the package after installation from the internet.
Next, you will get a list of available support packages. Click on “Arduino” and tick the option for MATLAB Support Package. Next, you are required to log in to your MathWorks account. After logging in accept the terms and conditions and continue to download the package.
Interfacing Arduino with MATLAB:
The next step is the interface of Arduino with MATLAB. First, connect your Arduino board to your computer running the MATLAB application. Next, type the following in the command window and enter,
a = arduino ()
This will connect Arduino and MATLAB and this will give you new properties such as COM Port, Name, and Available Pins etc. If you are connecting more than one Arduino board and you want to program a specific board then use the following command.
a = arduino (‘com8’, ’Mega2560’)
Programming Arduino using MATLAB:
Next we will get to the actual programming of the Arduino Board. We are using the Arduino Mega Board. It consists of an LED connected to Pin 13. We will be writing a MATLAB program which will enable the LED to blink 10 times with a delay of one second.
Go to the file tab and select NEW and click on “script Option”. You will enter the code we mention here and save the file. It will be saved as an extension for the MATLAB program named as an .m file. After this click on the Run option to run your program on Arduino to perform the operation.
Keep in mind that the program is not uploaded to Arduino so if you reset or restart the Arduino, it will be lost.
% create an arduino object a = arduino('com8', 'Mega2560'); % start the loop to blink led for 10 seconds for i = 1:5 writeDigitalPin(a, 'D13', 1); pause(1); writeDigitalPin(a, 'D13', 0); pause(1); end %end communication with arduino clear a
Applications of Arduino MATLAB Interface:
There are many applications of the Arduino MATLAB Interface:
- You can get analog and digital sensor data from the Arduino board
- You can build custom add-ons to interface with hardware and additional software
- You can create GUI (Graphical User Interface) with MATLAB
- You can analyze sensor data using signal processing, mathematical modeling and image processing
- Projects such as Color Detection and Object tracking can also be implemented.
For Dozen of Projects and Complete Guide about interfacing of Arduino with Matlab | i will recommend this BOOK Interfacing Arduino with MATLAB | E-Book
“Normally a software by the name of Arduino IDE is used which uses Java for coding.“
Ah yes? Since when?