Sensor Component

The sensor component provides an API for getting measurements.

If you have a physical sensor, an API endpoint, or anything else that provides measurements, use a sensor component.

Error

Configuration

To use a sensor and get its measurements, you need to add it to your machine’s configuration. Physical sensors often require a board component with a configured analog-to-digital converter (ADC). Virtual sensors often function without additional dependencies.

Go to your machine’s CONFIGURE page, and add a model that supports your sensor.

The following list shows the available sensor models. For additional configuration information, click on the model name:

Model
Description
ModelDescription
ultrasonicHC-SR04 ultrasonic sensors
Measuring movement or power or working with a motor?
  • If your sensor measures GPS, IMU, position, velocity, or acceleration, use a movement sensor.
  • If your sensor measured voltage, current, or power consumption of connected hardware use a power sensor.
  • If your sensor detects speed and direction of rotation of a motor or a joint, use an encoder.

API

The sensor API supports the following methods:

Method NameDescriptionviam-micro-server Support
GetReadingsGet the measurements or readings that this sensor provides.

ReconfigureReconfigure this resource.

DoCommandExecute model-specific commands that are not otherwise defined by the component API.
GetResourceNameGet the ResourceName for this sensor with the given name.

CloseSafely shut down the resource and prevent further use.

Troubleshooting

If your sensor is not working as expected, follow these steps:

  1. Check your machine logs on the LOGS tab to check for errors.
  2. Review your sensor model’s documentation to ensure you have configured all required attributes.
  3. Check that any wires are securely attached to the correct pins, if appropriate.
  4. Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the sensor there.

If none of these steps work, reach out to us on the Community Discord and we will be happy to help.

Next steps

For general configuration and development info, see:

To capture data from the sensor, see the data management service.