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:
- Read, write, and analyse data from Arduino sensors
- Develop algorithms that run standalone on the Arduino device
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:
- Set up the Matlab using package for Arduino
- Control Arduino to Blink LED by send a command to it using Matlab.
- Build a simulation Model.
- Download and run the Model on Arduino Uno.
- The Matlab Support Packages for Arduino Hardware lets you use Matlab to communicate with your board through USB cable.
- Matlab software
- MathWorks Account
- 220 Ohm Resistor
- Light- Emitting- Diode (LED)
- Jumper leads.
Before going further, you have to install Matlab using MathWork Account, then open it and the interface will look like this.
- Connect D9 on Arduino with the Resistor
- Connect other leg of Resistor to the long leg of LED
- Connect short Leg of LED to the GND
- Turn on the Arduino and connect it to the Laptop.
Connect the components as the figure bellow:
- Click on + Add- Ons on the top right of interface, then Get Hardware Support Packages, to download support package for Arduino.
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:
- Set analog and digital sensor data from your Arduino board
- Control other devices with digital and PWM outputs
- Drive DC, servo, and stepper motors (also supports Adafruit Motor Shield)
- Access peripheral devices and sensors connected over I2C or SPI
- Communicate with an Arduino board over a USB cable or wirelessly over Wi-Fi
- Build custom add-ons to interface with additional hardware and software libraries
Share this post
- 0 comment
- Tags: LED, limit, MCU's, microcontrollers, nodemcu, power, power supply, powerup, resistors, reverse engineering, tutorial, Webserver, xbee, zigbee