Arduino Simulink Digital Input example | applied electronics engineering

Latest

Arduino Simulink Digital Input example

By Applied Electronics - Thursday, February 23, 2017 No Comments
In this arduino tutorial we show how to use the arduino simulink digital input block with example of reading a switch state. The digital input block that you can find in the Simulink Support for Arduino Hardware library in the simulink can be used to read digital signal values like on/off state from a switch. We will thus use a switch connected to one of the digital pin of the arduino board as a demonstration of how to use the digital input block. Also a LED will be connected to another pin which will turn on if the switch is turned on and vice versa. This LED will thus indicate that the simulink is working correctly and the arduino microcontroller is indeed reading the switch.

First connect the Switch and a LED as shown in the figure below.


The schematic of the picture above is shown below.


The switch is connected to pin 8 of the arduino. Between pin 8 and the switch the wire is grounded using 10KOhm resistor. The other side of the switch is connected to the 5V supply of the arduino via breadboard. The LED is connected to pin 7 and grounded using 220Ohm resistor.

Next, we have to create a new model in simulink and then configure the simulink so that it recognizes the arduino board.

First create or open a new simulink model. In the model put a digital input and digital output blocks from the Simulink Support for Arduino Hardware > Common into the simulink model. Your model should look like the following.


Double click on Digital Input block and change the pin number to 8 and change the sample time to 0.1. Similarly double click and change the pin number of the digital output block to 7. These digital output and digital input are same as using the Arduino digitalWrite and digitalRead functions.

Now we have to configure the simulink to work with arduino. Go to the Tools > Run on Target Hardware > Options and then in the Hardware Implementation choose Arduino UNO as your Hardware board and ATMEL as your device vendor. These steps are shown below.



Click OK and exit.

Next we have to configure the run time and deployment method. Write inf into the run time and change the deployment to External as shown below.


Now the simulink setting is ready for simulation. Before we run the simulation, make sure you have connected the arduino USB to your computer. Then click on the Deploy to Hardware button which looks like RS232 connector or just Run the simulation by clicking on the Run button.

The program will be uploaded to your Arduino microcontroller and you should see this process by seeing that the led are blinking for few times. While the simulation is running, press the push button and obseve the LED. The LED should blink when the push button is pressed and not when not pressed.

Next see other arduino tutorials-

No Comment to " Arduino Simulink Digital Input example "