Arduino Simulink Tutorial 1 – LED blinking

How to program Arduino to blink LED using simulink

In this Arduino Simulink Tutorial 1 – LED blinking we shows how to blink LED connected to the Arduino UNO board using simulink. This is the first simulink arduino example where we show what you need to download, how to download, how to configure simulink to work with external hardware and finally real time simulation. Blinking LED is like Hello World program when testing microcontroller based hardware for the first time. So it good to know because it will help you whether things are properly configured, whether things are correctly working or not and the basic steps.

It good to point out here that this tutorial is basically the same as LED blinking using arduino IDE sketch program where digitalWrite function is used or using matlab script program where writeDigitalPin function is used. The only difference is that this is done via simulink.

Installation of Simulink Support Package for Arduino Hardware

In order that Arduino hardware can communicate with Simulink you need to download and install Simulink Support Package for Arduino Hardware. If you don’t already have installed the Arduino hardware support for simulink follow this step to download and install the Simulink hardware support for Arduino.

To add Simulink Support Package for Arduino Hardware start Matlab Software and look for Add-Ons at the top. Click on that Add-Ons button and search for Simulink Support Package for Arduino Hardware and download and installed it.

This step is shown below.

Installation of Simulink Support Package for Arduino Hardware

Create Simulink Model

Create a new blank simulink model page. On the simulink model add the Pulse Generator from simulink/commonly used blocks or simulink/sources library and the Digital Output from the simulink support package for arduino hardware library/common.

How to add these is shown below.

Create Simulink Model

Now simple connect the Pulse Generator to the Digital Output block as shown below.

 Pulse Generator to the Digital Output block

Then double click the Digital Output block and change the Pin number to 8 then click ok to save. Then double click on the Pulse Generator block and change the sample time to 0.5 second. Click ok to exit. This is shown below.

How to program Arduino to blink LED using simulink

Arduino Hardware Connection

Next step is to connect a LED to Arduino Hardware. Connect the LED positive to the Arduino digital pin 8 and the LED negative a 220Ohm resistor. Then connect the other end of the resistor to the ground. The connection diagram is shown in the schematic below.

Arduino Hardware Connection

Or as shown in the figure below.

Arduino Simulink Tutorial 1 - LED blinking

Now plug in the USB to your computer.

Simulink Configuration

Next we have to configure Simulink to use the Arduino Board and set the com port properly. To do this there are two ways. Either you can go to the Simulation > Model Configuration Parameter > Hardware Implementation and set your Arduino board to use there as shown below,

Simulink Configuration

or, you can configure which board to use from the Tools > Run on Target Hardware > Options which is shown below.

And in both cases select your board to use. In this example, Arduino UNO has been used.

Running Simulation with External Hardware Arduino UNO

In this final step we run the simulink model. But before doing that we have to tell matlab/simulink to use the external device which in this case is the Arduino hardware. This is done by selecting External in the deployment option.Also enter “inf” into run time field. Click on Deploy to Hardware button or the run button to start the simulation. How to do this is also shown below.

Running Simulation with External Hardware Arduino UNO

At this point the LED should be blinking. If so you have successfully completed this tutorial Arduino Simulink Tutorial 1 – LED blinking.

If your LED is not blinking or if you get error then there are few things you try. Unplug and plug the USB cable and see it this solve the problem. Try to see if you can program using Arduino IDE and arduino program code.

See also other Arduino tutorials:

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

Your email address will not be published. Required fields are marked *

Arduino Due tutorial - Blinking LED

Arduino Due tutorial – Blinking LED

digitalRead and digitalWrite - Arduino Proteus Tutorial

digitalRead and digitalWrite – Arduino Proteus Tutorial