diff --git a/programming/arduino/sr_firmware.md b/programming/arduino/sr_firmware.md index 3b0958b7..5bb5d01e 100644 --- a/programming/arduino/sr_firmware.md +++ b/programming/arduino/sr_firmware.md @@ -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) +``` + +
+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. +
diff --git a/simulator/simulated_robot.md b/simulator/simulated_robot.md index 0e3eb8b0..b0220803 100644 --- a/simulator/simulated_robot.md +++ b/simulator/simulated_robot.md @@ -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).
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.