Wednesday, February 10, 2016

Blink an LED using Arduino and Matlab Simulink

If you are looking to make your arduino talk wiith Matlab, usually this is done by serial communication between Matlab and arduino, where we separately write program for Matlab and arduino, we pass data from and process in Matlab, but you don't need to do such things any more, Matlab developed a software for interfacing low cost hardware like arduino, Beaglebone black, Raspberry pi etc.,   You can use any of the arduino hardware with Matlab, try to use Arduino Mega or Due, the most popular Arduino boards lack of memory and process will slow down when program from simulink. to follow this tutorial you need to install arduino support package to continue this tutorial, you can check my other blog post on how to install support for arduino in Matalb. you can do many interactive project using matlab and arduino. 


here is a tutorial to show you how to program Arduino from Matlab simulink, a powerful graphical programming language which is used in industries. In this tutorial you will learn about how to blink an LED using Arduino and programming from Matlab Simulink. before starting this tutorial check out the introduction section to know about what are the needs to get started with this tutorial and how to install the software and hardware requirements.






Check the video below to know how to control an LED by using Matlab, if you are not sure about how to install the Hardware support for arduino in Matlab check the tutorial here


Steps to make the LED blink

Connect your LED to the 3rd Pin or any other pin you would like and connect your Arduino to your Laptop or PC

Start your Matlab
Click on the Simulink Library.

Once the library browser opened click on the New model from the simulink library.


after the new model window open save your new model by giving any name you like and click on the Simulink support Package for Arduino Hardware from the Simulink library Browser



Open the Common box in the library and choose Digital Output block , drag and drop the digital output block in the model window.



Double click on the Digital Output block and change the pin number to whatever pin number the LED has connected in this case I have connected my LED to the 3rd pin of Arduino Mega



after completing the above steps, got the library browser and select sources from the browser, after opening the sources blocks click the signal generator block and drag it to model window and connect the signal generator to the digital output block by pointing the arrow towards the digital output from signal generator.



Double click on the Pulse generator change the Time(t) to pulse type to sample based.



and also change the sample time to 0.01 and click OK to close the pulse generator parameters.



Change it to external connector and also the simulation time to infinite.





click the tools and select run on target and choose prepare to run. once the window opens click on the Enable hardware specification and from the Hardware board select Arduino Mega



choose the board and click ok, once you pressed ok it will move to the device details don't change any parameters leave everything as same and click ok.


click the run button to temporarily run your code on Arduino which allow us to verify the program if you are not satisfied with the result you can go and change the code until get the desired results and if the program is perfect you can permanently deploy the code by just pressing the deploy to hardware button available in the Model window.



2 comments :

Post a Comment