This tutorial will teach you basics about control Arduino using MatLab and learn how to do simple project like blinking an LED.
What is Matlab:
Is a high-performance language allows implementation of algorithms, creation of user interfaces and technical computing. Where problems and solutions are expressed in familiar mathematical notation and can interfacing with programs written in other languages, such as C, C++, Java, and Python.
Matlab supports two primary workflows using the simple traditional Arduino programming:
What is Arduino:
Is an open source, computer hardware and software company for building digital and interact with devices, Arduino board are able to - light on a sensor, turning on an LED and control motor.
After this tutorial, you will learn how:
Before going further, you have to install Matlab using MathWork Account, then open it and the interface will look like this.
Connect the components as the figure bellow:
2. A new interface will open, choose internet (recommended) and go to next.
3. Now you will see a list of many Support Package, choose Support Package for Arduino and click next
4. Log in to your MathWork Account, chick I accept box, click next, next and finally install.
Note: installation will take a while, so please be a patient.
5. Click finish and now you will be able to control Arduino using Matlab.
6. Click on Simulink Library , new window will open and you will see a list on the left, click on plus sign behind Simulink Extras and go to Simulink Support Package for Arduino
7. On top lift of the same interface, click on and you will notice the anther new interface will open, click on Digital Output and drag it to those new interface.
8.Double Click on Digital Output and chick the pin number if it 9 or not, if not change it to 9 and press OK
Note: you can send commands to Arduino based on pin number, So here you will control LED over D9 on Arduino board.
9.Go to the list of libraries, click on Sources and drag Pulse Generator behind Digital Output
10. Double Click on Pulse Generator, on Parameters Fields, choose Sample based as Pulse type, 10 as Period, 5 as Pulse width and 0.1 Sample time then press OK.
11.Click on Sinks where you can find it on list of libraries, drag Scope to the same window with Pulse Generator and Digital Output.
12.Connect Pulse Generator with Scope, click on run on the top of window and double click on Scope, a new window will open that show the pulses generated by pulse Generator.
Note: That pulses will sent to Arduino to blink the LED, when high pulse, LED will turn on and when low pulse, LED will turn of and so on.
13.Delete Scope (by click on it then press delete on keyboard), connect pulse Generator with Digital Output and save your work as new file.
14.Click on Tools, then run on target hardware and prepare to run, select Arduino Uno as target Hardware, automatically as set host COM port, default as analog input reference voltage and 9600 as serial baud rate, Now the commands will download to Arduino and you can start communicating with it.
15.Click again on Tools and Run. Here notice the LED, it should blinking and the project finish.
Now you have basics about Matlab communicating Arduino and you can do more and more projects using it such as: