Measures distance between NXT ultrasonic sensor and the nearest object
Simulink® Support Package for LEGO® MINDSTORMS® EV3 Hardware / NXT Sensors
The NXT Ultrasonic Sensor measures the distance between the NXT ultrasonic sensor on the LEGO MINDSTORMS EV3 brick and the nearest object in front of the sensor.
The sensor can detect objects from approximately 5–255 centimeters away.
When the nearest object is beyond the maximum range of the ultrasonic sensor, the
sensor outputs the maximum value,
The measured distances are approximate. For greater precision, calibrate the sensor output values against physical measurements.
The distance from which the sensor first detects an approaching object depends on:
The ultrasonic reflectance of the object, which is a function of the object’s size and composition. The sensor detects large hard objects from a greater distance than small soft ones. For example, the sensor might detect a pane of glass at 255 centimeters and a hand puppet at 150 centimeters.
The angle of incidence of the object relative to the sensor. The sensor detects objects directly in front of it at greater distances than the objects to its side.
During simulations without hardware, this block emits zeros. See Block Produces Zeros or Does Nothing in Simulation (Simulink).
legoev3nxtlib block library and copy the
NXT Ultrasonic Sensor block to a new model.
legoev3lib block library and copy the
Motor block to the same
model and connect these blocks.
Connect the ultrasonic sensor to port 1 and a servo motor to port A of the EV3 brick.
Prepare and run the model on the EV3 brick as described in Run Model on EV3 Hardware.
Hold the ultrasonic sensor closer to an object and observe that the speed of the motor decreases.
Select the EV3 sensor port to which the sensor is connected. Avoid
assigning multiple devices to the same port. The options are
Specify how often the block reads sensor values. This value defaults
0.1. Shorter sample times, such as
0.01, may produce unreliable measurements.
Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.