main content

measure distance between ultrasonic sensor and object -凯发k8网页登录

measure distance between ultrasonic sensor and object

since r2018b

  • ultrasonic sensor block

libraries:
simulink support package for arduino hardware / sensors

description

the ultrasonic sensor block outputs the distance between the ultrasonic sensor connected to the hardware and the nearest object in front of the sensor. the block outputs the distance as a double-precision value, in meters. if the object is placed beyond the range of sensor detection, the block outputs 0.

if you simulate a model that contains the ultrasonic sensor block without connecting the hardware, the block outputs zeros. for more information, see .

ports

output

the port outputs the distance between the ultrasonic sensor connected to the hardware and the nearest object in front of the sensor. the block outputs the distance in meters. if the object is placed beyond the range of sensor detection, the port outputs 0.

data types: double

parameters

select the number of signal pins on the ultrasonic sensor to send and receive sound waves.

  • 1 — if the ultrasonic sensor has only one signal pin, sig, select 1.

  • 2 — if the ultrasonic sensor has two separate signal pins, trig and echo, select 2.

select the digital pin on the hardware to which the trig pin of the ultrasonic sensor is connected. for information about the digital pin numbers on the hardware, click view pin map.

to know how to assign pins for the block, see .

dependencies

the trigger pin parameter appears only when you set the number of signal pins parameter to 2.

select the digital pin on the hardware to which the echo pin of the ultrasonic sensor is connected. for information about the digital pin numbers on the hardware, click view pin map.

to know how to assign pins for the block, see .

dependencies

the echo pin parameter appears only when you set the number of signal pins parameter to 2.

select the digital pin on the hardware to which the sig pin of the ultrasonic sensor is connected. for information about the digital pin numbers on the hardware, click view pin map.

to know how to assign pins for the block, see .

dependencies

the signal pin parameter appears only when you set the number of signal pins parameter to 1.

specify how often the block reads distance using the ultrasonic sensor, measured in seconds.

when specifying sample time, verify these settings to avoid task overrun:

  1. the sample time parameter must be equal to the model base rate. to view the model base rate, select display > sample time > all on the model toolbar. in the sample time legend dialog box, the value corresponding to the red box is the base rate of the model.

  2. the sample time parameter and the model base rate must be greater than the total time required by the sensor to transmit and receive the sound wave. for example, if the object is placed 0.1 meters away from the sensor, the sample time parameter specified must be greater than 3.01 seconds.

    for information on how to calculate the travel time of the sound wave, see calculate travel time of sound wave.

more about

version history

introduced in r2018b

see also

|

网站地图