Distance to object in front of ultrasonic sensor
arduino object with
arduinoObj = arduino('COM9','Uno','Libraries','Ultrasonic');
Create an ultrasonic sensor connection object with the trigger pin set to D2 and echo pin set to D3.
ultrasonicObj = ultrasonic(arduinoObj,'D2','D3')
ultrasonicObj = Ultrasonic with properties: TriggerPin: 'D2' EchoPin: 'D3'
Measure the distance to the object.
distance = readDistance(ultrasonicObj);
distance— Distance to object
Distance to object, specified as a positive real scalar, in meters. If the
object is not in the range of the sensor, the function returns