Skip to content

Commit

Permalink
Add docs for ultrasound function on arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Aug 24, 2024
1 parent 57f4814 commit bcba4da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions programming/arduino/sr_firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,20 @@ However, for simple electronics, a microswitch for example, you would normally b
However, the built-in pull-up resistor alleviates this need.
It essentially wires in a resistor connected to 5.0V, meaning that when this option is enabled, an input pin will "default" to being high.
This means you can simply connect a switch between the input pin and a ground pin without any need of resistors - when the switch is open, the pin will read high; when closed, it will read low.

## Ultrasound Sensors

You can also measure distance using an ultrasound sensor from the arduino. Ultrasound sensors return the distance of the closest object in mm.

```python
# Trigger pin: 4
# Echo pin: 5

# Measure distance in mm
distance_mm = robot.arduino.ultrasound_measure(4, 5)
```

<div class="warning">
The ultrasound sensor can measure distances up to 4 metres.
If the ultrasound signal has to travel further than 4m, the sensor will timeout and return 0.
</div>
2 changes: 1 addition & 1 deletion simulator/simulated_robot.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ They return the distance to the nearest object in front of the sensor in a narro
Objects beyond 4 meters are not detected.

The robot has four ultrasound sensors attached to it, one on each side of the robot.
They can all be accessed using the Arduino API's [ultrasound interface]({{ site.baseurl }}/programming/arduino/sr_firmware#ultrasound).
They can all be accessed using the Arduino API's [ultrasound interface]({{ site.baseurl }}/programming/arduino/sr_firmware#ultrasound-sensors).

<div class="info">
Since these sensors rely on echoes being reflected back from objects, if the angle of incidence between the sensor's pulse and the contacted surface exceeds 22.5 degrees then the sensor will be unable to detect the object.
Expand Down

0 comments on commit bcba4da

Please sign in to comment.