class devices.Ultrasonic(ev3handle, layer=1, portnum=1, inputmode=None)[source]

The class to represent the EV3 ultrasonic sensor.

Set up an ultrasonic sensor on port number 3

>>> from pyev3.brick import LegoEV3
>>> from pyev3.devices import Ultrasonic
>>> myev3 = LegoEV3(commtype='usb')
>>> mysensor = Ultrasonic(myev3, portnum=3, inputmode='distance')
  • ev3handle (object) – LegoEV3 instance representing the EV3 brick.

  • layer (int) – The layer of the brick 1 or 2 in a daisy-chain configuration.

  • portnum (int) – The brick input port connected to the sensor. Possible values are 1, 2, 3, or 4.

  • inputmode (str) –

    • 'distance' measure distance to an object in cm

    • 'listen' detect presence of other ultrasound source


Displays a summary with the sensor information.

property inputmode

Contains the sensor input mode. Use this to change the mode on the fly (read/write).

property output

Contains the sensor output based on the inputmode (read only).

  • 0 to 250 (inputmode=’distance’)

  • 0 or 1 (inputmode=’listen’)