This example shows you how to write a MATLAB script to implement a collision alarm with LEGO® MINDSTORMS® EV3™ hardware.
The MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware enables you to interact with LEGO MINDSTORMS EV3 hardware from within MATLAB. You can use MATLAB scripts to implement more complex functionality for EV3 hardware.
This example demonstrates a collision alarm implementation with EV3 brick and Ultrasonic sensor. As an object gets closer to the Ultrasonic sensor, the EV3 brick generates a higher-pitched alarm sound.
This example requires additional hardware:
EV3 Ultrasonic Sensor
1. Follow the instructions in Getting Started with MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware example to set up communication between your host computer and EV3 brick.
2. Connect Ultrasonic sensor to an input port of EV3 brick.
1. Open the collision alarm script template
2. Run script.
Click Run button to run the collision alarm script.
Reset the detection range by changing
RANGE = 0.3
the value of RANGE from 0.3 meters to another value, such as 0.5 meters.
Rerun the script to observe the behavior change.
Press EV3 UP button to quit while-loop and stop the script, which is implemented as
while ~readButton(mylego, 'up')
This example demonstrates using a MATLAB script that to implements a collision alarm. You learned the basic MATLAB script framework to implement more complex functionality for EV3 hardware.