Introduction: Using MATLAB App Designer With Arduino
MATLAB App Designer is a powerful tool that allows you to design Graphical User Interfaces (GUIs) with all of the MATLAB functionalities.
In this tutorial we are going to make a GUI to control the brightness of a LED through an easy to follow steps.
Note: This Tutorial uses Arduino hardware support package on MATLAB, for more information please visit https://www.mathworks.com/hardware-support/arduino-matlab.html
Step 1: Opening App Designer
Start by opening MATLAB and creating a new App Designer file.
Step 2: Designing the App
Press save at the top left corner of the screen and name it DimmingLED.
Drag a Label from the component library into the central design area.
Drag a knob while holding control key to prevent App Designer from adding a label along side with the knob.
Press on the Label, then change the text to Duty Cycle and the size to 36.
Step 3: Connecting the Arduino
Connect the Arduino through the USB port(in my case I’m using Arduino nano).
wire an LED and a resistor as in the following schematic.
Go back to the App Designer and Click on CodeView above the design area.
insert a private property from the top left corner of the screen.
remove the property name and name it “a”.
From the component browser right click on app.UIfigure and choose Add StartUpFcn callback.
Write: app.a = Arduino();
From the Component Browser right click on app.knop and choose Add ValueChangingFcn callback.
Write The following to it , then press Run.
changingValue = event.Value;
app.DutyCycleLabel.Text = char(string(changingValue) + ' %');
writePWMDutyCycle(app.a, 'D3', changingValue/100.0);
Step 5: Congratulations
Now you can control the LED Brightness from your newly created app