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.
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:
Add support for other models
If none of the existing models fit your use case, you can create a modular resource to add support for it.
Model | Description |
---|---|
ultrasonic | HC-SR04 ultrasonic sensors |
Add support for other models
If none of the existing models fit your use case, you can create a modular resource to add support for it.
viam-micro-server
works differently from the RDK, so creating modular resources for it is different.
Refer to the Micro-RDK Module Template on GitHub for information on how to create custom resources for your viam-micro-server
machine.
You will need to recompile and flash your ESP32 yourself instead of using Viam’s prebuilt binary and installer.
API
The sensor API supports the following methods:
Method Name | Description | viam-micro-server Support |
---|---|---|
GetReadings | Get the measurements or readings that this sensor provides. | |
Reconfigure | Reconfigure this resource. | |
DoCommand | Execute model-specific commands that are not otherwise defined by the component API. | |
GetResourceName | Get the ResourceName for this sensor with the given name. | |
Close | Safely shut down the resource and prevent further use. |
Troubleshooting
If your sensor is not working as expected, follow these steps:
- Check your machine logs on the LOGS tab to check for errors.
- Review your sensor model’s documentation to ensure you have configured all required attributes.
- Check that any wires are securely attached to the correct pins, if appropriate.
- 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.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!