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.
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
Android model 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.
LEGO MINDSTORMS EV3 model 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.
Completing the Connect Android Device to LEGO MINDSTORMS EV3 example is recommended.
Android phone or tablet
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 the Android device and the LEGO MINDSTORMS EV3 robot
1. Open the Android 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 LEGO MINDSTORMS EV3 model.
4. Double-click on the TCP/IP Send block and change the Remote address to the IP address of the Android device.
5. In the Android model, click Deploy to Hardware to run this model on your Android device.
6. In the EV3 model, click Deploy to Hardware to run this model on your EV3 hardware.
7. Control the EV3 robot using the Android device.
This example showed you how to wirelessly control the movement of an EV3 robot by using an Android device.