«

»

Start With Arduino And Simulink

Hardware setup

وصل زي الصورة دي بالظبط

Connect an LED to an Arduino Output Pin

1. Attach one end of the 220 Ohm resistor to output pin 9 on the Arduino board. Use the recommended breadboard and the breadboard wires.

2. Attach the long leg (positive) of the LED to the resistor. Attach the short leg (negative) to the ground pin on the Arduino board.

 

Create the simulink model

                               ده النموذج  النهائي  اللي الاردوينو هيشتغل بيه بعد ما ننزله من الكمبيوتر للاردوينو و الخطوات الجاية هتقولك ازاي تعمل النموذج ده

 Review Arduino Block Library

Simulink Support Package for Arduino Hardware provides an easy way to create algorithms that use Arduino sensors and actuators by using the blocks that can be added to your Simulink model. The blocks are used to configure the associated sensors and actuators, as well as to read and write data to them.

Create a Model for Arduino Hardware

In this task, you will create a simple Simulink model that changes the state of the Arduino digital output pin.

1. In MATLAB, select HOME > New > Simulink Model.

2. Drag the Pulse Generator block from the Simulink Sources library to your model.

3. Double-click the Pulse Generator block. Set the Pulse type to parameter to Sample based and set the Sample time parameter to 0.1 second.

4. In the Simulink Library Browser, navigate to Simulink Support Package for Arduino Hardware > Common.

5. Double-click the Digital Output block. Review the block mask, which contains a description of the block and parameters for configuring the associated Arduino digital output pin.

6. Drag the Digital Output block to the model. Use the default block settings.

7. Connect the Pulse Generator block to the Digital Output block.

 Configure and Run the Model on Supported Arduino Hardware

1. Connect the Arduino board to your computer with a USB cable.

2. In your Simulink model, click Simulation > Model Configuration Parameters to open Configuration Parameters dialog.

3. Select the Hardware Implementation pane and select your required Arduino hardware from the Hardware board parameter list. Do not change any other settings.

4. Click OK.

5. In your Simulink model, click the Deploy to Hardware button on the toolbar. The model will now be deployed to the connected Arduino hardware.

6. Look at the LED attached to pin 9. The LED should blink one time every second.

7. Save your model.

Other Things to Try

Experiment with other blocks in the Arduino block library. For example:

  • Create and run a model that turns the LED on if a signal is applied to a digital input pin.

  • Create and run a model that repeatedly brightens and dims an LED. Hint: use the PWM block.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>