Configure an ultrasonic Sensor
Configure an ultrasonic
sensor to integrate an HC-S204 ultrasonic distance sensor into your robot:
Navigate to the Config tab of your robot’s page in the Viam app.
Click on the Components subtab and navigate to the Create component menu.
Enter a name for your sensor, select the type sensor
, and select the ultrasonic
model.
Click Create component.
Edit and fill in the attributes as applicable.
{
"components": [
{
"name": "<your-ultrasonic-sensor-name>",
"type": "sensor",
"model": "ultrasonic",
"attributes": {
"trigger_pin": "<pin-number>",
"echo_interrupt_pin": "<pin-number>",
"board": "<your-board-name>",
"timeout_ms": <int>
},
"depends_on": []
}
]
}
{
"components": [
{
"name": "your-ultrasonic-sensor",
"type": "sensor",
"model": "ultrasonic",
"attributes": {
"trigger_pin": "5",
"echo_interrupt_pin": "15",
"board": "your-board-name",
"timeout_ms": "1000"
},
"depends_on": []
}
]
}
The following attributes are available for ultrasonic
sensors:
Attribute | Type | Inclusion | Description |
---|---|---|---|
board | string | Required | The name of the board the sensor is wired to. |
trigger_pin | string | Required | The pin number on the board that you have wired the sensor’s trigger pin. |
echo_interrupt_pin | string | Required | The pin number of the pin the sensor’s echo pin is wired to on the board. If you have already created a digital interrupt for this pin in the board’s configuration, use that digital interrupt’s name instead. |
timeout_ms | int | Optional | Time to wait in milliseconds before timing out of requesting to get readings from the sensor. Default: 1000 . |
Have questions, or want to meet other people working on robots? Join our Community Discord.
Was this page helpful?
Glad to hear it! If there is anything we could be doing better, please create an issue.
We're sorry about that. If you'd like to talk to us for help, please join the Community Discord. To ensure we know what's wrong with this page, you can also open an issue.