Main Content

Control LEGO MINDSTORMS EV3 Robot Using Android Device

This example shows how to use the Accelerometer sensor data of an Android® device to control the motion of a LEGO® MINDSTORMS® EV3 robot.

Introduction

Android phones and tablets provide wireless connectivity and a graphical user interface. LEGO MINDSTORMS EV3 is a programmable robotics construction set. The EV3 Brick is a programmable intelligent Brick that acts as the brain of your robot, controls motors and sensors, and also provides wireless communication through Wi-Fi® and Bluetooth®. In this example, you learn how to control EV3 robot using an Android device by connecting them wirelessly.

This example provides two Simulink models

  • androidev3robot — In this model, you read the Accelerometer sensor data of an Android device and use the acceleration data to determine the motor speeds for an EV3 robot. A network connection is set up between the Android device and the EV3 robot for data exchange.If the distance information received from the EV3 is less than 10 cm, the Android device beeps.

  • ev3robot_android — In this model, the left and right motor speed received from the Android device are used to drive the motors of the EV3 robot. The distance of the obstacle present in front of EV3 robot, measured by ultrasonic sensor is sent to the Android device.

With these models, you will:

  • Set up a network connection between an Android device and an EV3 robot.

  • Configure and run a Simulink model for the Android device to send and receive TCP/IP packets to the EV3 robot.

  • Configure and run a Simulink model for the EV3 robot to receive and send TCP/IP packets from the Android device.

Prerequisites

Complete the Connect Android Device to LEGO MINDSTORMS EV3 example.

Required Hardware

  • Android device such as phone or tablet

  • EV3 Brick

  • Two EV3 Large Motors

  • EV3 Ultrasonic sensor

  • EV3 Wi-Fi Dongle

Working Principle of Robot Motion Control

The acceleration data of the Android device is used to control the motion of the robot.

From the Accelerometer data, you can mathematically determine the value of pitch and roll for a given position of the Android device. Then you can map the pitch and roll movement of the Android device to the motion of the EV3 robot. The pitch represents the forward and reverse motion of the motor. The roll represents the sideways motion of the robot.

In the provided Android model, a MATLAB Function block models the mathematical equations required to convert the pitch and roll values to the linear speed of the motors.

A communication link for data exchange is set up between the Android device and the EV3 brick. The linear motor speed derived from the pitch and roll values is sent over TCP/IP from the Android device to the EV3. The EV3 receives this data and uses it as input to drive the two motors.

Task 1 - Set Up LEGO MINDSTORMS EV3 Robot

1. Build a two-wheeled robot. You can build a robot similar to the one described in the printed building instructions in the education core set or as shown here.

2. Connect the ultrasonic sensor to port 1 of the EV3 brick. Place the sensor in front of the robot as shown in the image.

Task 2 - Configure and Run Models on Android Device and LEGO MINDSTORMS EV3 Robot

1. Open the androidev3robot Simulink model.

2. Double-click on the TCP/IP Send block and change the Remote address to the IP Address of the EV3.

3. Open the ev3robot_android Simulink model.

4. Double-click on the TCP/IP Send block and change the Remote address to the IP address of the Android device.

5. On the Hardware tab of the Android Simulink model, in the Mode section, select Run on board and then click Build, Deploy & Start to run this model on your Android device.

6. On the Hardware tab of the EV3 Simulink model, click Build, Deploy & Start to run this model on your Android device.

7. Control the EV3 robot using the Android device.