measure distance between ultrasonic sensor and object -凯发k8网页登录
measure distance between ultrasonic sensor and object
since r2018b
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
port_1 — distance between ultrasonic sensor and nearest object in front of
sensor
scalar
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
number of signal pins — number of signal pins on ultrasonic sensor
1
(default) | 2
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, select1
.2
— if the ultrasonic sensor has two separate signal pins, trig and echo, select2
.
trigger pin — digital pin connected to trig pin
4
(default) | any valid pin number
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
.
echo pin — digital pin connected to echo pin
5
(default) | any valid pin number
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
.
signal pin — digital pin connected to sig pin
3
(default) | any valid pin number
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
.
sample time — interval to read distance using ultrasonic sensor
0.1
(default) | -1
| any nonnegative value
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:
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.
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
calculate travel time of sound wave
in this example, the object is 0.1 meters away from the sensor.
calculate the travel time (t) of the sound wave using the formula:
t = d / s, where d is the distance between the sensor and the object. s is the speed of sound in air, which is approximately 332 meters per second (m/s). in this example, as the object is placed 0.1 m away from the sensor:
= 0.1 / 332
= 0.000301 seconds
the sample time parameter specified must be greater than
0.000301
seconds.
version history
introduced in r2018b
see also
|
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)