Skip to content

Search the documentation

Kit
Firmware

DistanceSensor

Smart Car

Measures how far away something is. It sends out a short burst of ultrasound, a sound too high for us to hear, and times how long the echo takes to come back, like a bat.

The DistanceSensor class is reached through this attribute of robot.

Can be None.

All the attributes of robot are in its table. Read Attributes that can be None to see when a part is None.

How far the nearest object is, in centimetres; -1 when the reading fails.

distance_cm() -> float

Used in examples: Sensor check

How far the nearest object is, in millimetres; -1 when the reading fails.

distance_mm() -> int

Used in examples: Sensor check

True when something is within_cm centimetres away or closer (default 10).

sees_object(within_cm: int) -> bool

You can leave out within_cm.

Used in examples: Sensor check