Control Brightness of Arduino Onboard LED from Android Device
This example shows how to control the brightness of the Arduino LED from an Android device.
Android devices provide wireless access and a user interface. Arduino is an open-source platform used for building electronics projects. Arduino consists of both a hardware board with a micontroller and a software Integrated Development Environment (IDE) that runs on your computer Using these two, you can, for example control Arduino hardware using an Android device by connecting them wirelessly.
This example provides two Simulink models,
With these models, you will:
- Set up a network connection between an Android device and Arduino
- Configure and run Simulink models for Android device and Arduino to remotely control the brightness of the LED on the Arduino.
- Download and Install Simulink Support Package for Android Devices (required)
- Download and Install Simulink Support Package for Arduino Hardware (required)
- Complete the Getting Started with Android Devices example.(recommended)
- Complete the Getting Started with Arduino Hardware example.(recommended)
- Complete the Getting started with WiFi on Arduino Hardware example.(recommended)
- Arduino Mega 2560/Mega ADK/Due/Leonardo/MKR1000
- Android phone or tablet
- Arduino WiFi Shield/ ESP8266
Task 1 - Configure the Model for Supported Arduino Hardware
You can skip this task if you are using the Arduino Mega ADK board.
In this task, you will configure the model for the supported Arduino board.
1. In your Simulink model, click Simulation > Model Configuration Parameters to open Configuration Parameters dialog.
2. Select the Hardware Implementation pane and select your required Arduino hardware from the Hardware board parameter list. Do not change any other settings.
3. Click OK.
Task 2 - Configure Network Connection
Set up a network connection between an Android device and an Arduino. The communication protocol used in this example is TCP/IP.
1. Connect the WiFi hardware to the Arduino board.
For more details on connecting the Arduino to WiFi Shield, see Connect Arduino WiFi Shield to Arduino Hardware.
For more details on connecting the Arduino to ESP8266, refer to Connect ESP8266 to Arduino Hardware in the documentation.
The Arduino MKR1000 has an on-board WiFi chip. It can be used directly without any additional WiFi hardware.
2. Open the Arduino model. To configure the network settings for the Arduino WiFi Hardware, go to Configuration Parameters > Hardware Implementation > Target hardware resources > WiFi properties.
3. Specify the SSID of your WiFi network in the Service set identifier (SSID) parameter.
4. Select the WiFi encryption parameter based on your WiFi network encryption settings.
For more details on configuring the network settings for Arduino WiFi Hardware, see
5. Connect your Android device to the same WiFi network to which the Arduino is connected.
Task 3 - Configure and Run Models on Android Device and Arduino Hardware
1. Open the Arduino model.
2. Click Deploy to Hardware button of Arduino model to run this model on your Arduino hardware
3. In the Diagnostic viewer, find the dynamically assigned IP address of Arduino below the memory usage information. Alternatively, a MATLAB base workspace variable with the name modelname_IPaddress is created with the value of the IP address.
4. Open the Android model.
5. Double-click on the TCP/IP Send block and change the Remote address to the IP address of the Arduino hardware.
6. Click Deploy to Hardware button of Android model to run this model on Android device.
7. In the Android device, change the Slider value on Android device to control the brightness of LED.
Other Things to Try
- Replace WiFi Block in Arduino model with Ethernet block.
- Connect the Arduino hardware to the electronic appliances using relays and with the help of button Block on Android, control them.
This example showed you how to
- Wirelessly connecting an Android smartphone to Arduino using TCP/IP.
- Remotely control the brightness of an Arduino onboard LED using the Android Slider block.