|
| 1 | + |
| 2 | +[](https://github.com/marketplace/actions/arduino_ci) |
| 3 | +[](https://github.com/RobTillaart/US500/actions/workflows/arduino-lint.yml) |
| 4 | +[](https://github.com/RobTillaart/US500/actions/workflows/jsoncheck.yml) |
| 5 | +[](https://github.com/RobTillaart/US500/issues) |
| 6 | + |
| 7 | +[](https://github.com/RobTillaart/US500/blob/master/LICENSE) |
| 8 | +[](https://github.com/RobTillaart/US500/releases) |
| 9 | +[](https://registry.platformio.org/libraries/robtillaart/US500) |
| 10 | + |
| 11 | + |
| 12 | +# US500 |
| 13 | + |
| 14 | +Arduino library for US500 underwater distance sensor. |
| 15 | + |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +**Experimental** |
| 20 | + |
| 21 | +This library is to use the US500 underwater (IP67) distance sensor. |
| 22 | +The sensor communicates over Serial at 9600 baud. |
| 23 | +The MCU sends a command and depending on the command the device answers. |
| 24 | + |
| 25 | +The device can read a distance in the range from 0.5 to 50 centimetre (0.2 - 20 inch). |
| 26 | +The accuracy is ±2mm (~0.1 inch). |
| 27 | +The field of view is ±5°. |
| 28 | +The US500 can also read the temperature of the water typical 0-100°C. |
| 29 | +Furthermore the device has a start and stop function. |
| 30 | +These functions are straight forward. |
| 31 | + |
| 32 | +The library is not tested with hardware (order pending). |
| 33 | + |
| 34 | +It is unknown how the device behaves in other liquids, at least the distance |
| 35 | +measurements are expected to be incorrect (other speed of sound). |
| 36 | + |
| 37 | +The device might need a separate power supply (75mW @ 5V). |
| 38 | + |
| 39 | +Feedback, as always is welcome. |
| 40 | + |
| 41 | + |
| 42 | +### Connections US500 |
| 43 | + |
| 44 | +The US500 device is connected to a controller board (which is NOT waterproof). |
| 45 | + |
| 46 | +| Colour | Connection | Notes | |
| 47 | +|:--------------|:-------------|:--------| |
| 48 | +| Gray core | D signal + | polarity !! |
| 49 | +| Gray shield | D signal - | polarity !! |
| 50 | +| Black | Temp NTC | |
| 51 | +| Black | Temp NTC | |
| 52 | + |
| 53 | +The temperature sensor has no preferred orientation, however the GRAY |
| 54 | +distance cable can only be connected in one way. |
| 55 | + |
| 56 | + |
| 57 | +### Compatible |
| 58 | + |
| 59 | +The US4000 (up to 4 meter, IP68) is almost compatible with the US500. |
| 60 | +Main difference is the address and the setDistance() call is not supported. |
| 61 | +A future update is planned to support the US4000. |
| 62 | + |
| 63 | + |
| 64 | +### About hardware |
| 65 | + |
| 66 | +It is not know what the resistance of the NTC is, otherwise it might be connected |
| 67 | +with voltage divider to an analog port (possible improve resolution?). |
| 68 | + |
| 69 | +It is also not clear what the protocol of the distance sensor is. |
| 70 | +The transducer operates with a 3.3 MHz frequency. |
| 71 | +Assumption is it will send a short pulse and waits for the echo. |
| 72 | + |
| 73 | + |
| 74 | +### Speed of sound in water |
| 75 | + |
| 76 | +It is unknown if the US500 compensates for the temperature of the water. |
| 77 | +One may assume it does. |
| 78 | + |
| 79 | +From - https://www.engineeringtoolbox.com/sound-speed-water-d_598.html |
| 80 | +(has also a Fahrenheit => feet/sec table) |
| 81 | + |
| 82 | +| temp °C | Speed m/s | Speed m/s | Diff % | |
| 83 | +|:---------:|:------------:|:------------:|:--------:| |
| 84 | +| | WATER | SEAWATER | | |
| 85 | +| 0 | 1403 | 1449 | 3.28 | |
| 86 | +| 5 | 1427 | | | |
| 87 | +| 10 | 1447 | 1490 | 2.97 | |
| 88 | +| 20 | 1481 | 1522 | 2.77 | |
| 89 | +| 30 | 1507 | 1546 | 2.59 | |
| 90 | +| 40 | 1526 | 1563 | 2.63 | |
| 91 | +| 50 | 1541 | | | |
| 92 | +| 60 | 1552 | | | |
| 93 | +| 70 | 1555 | | | |
| 94 | +| 80 | 1555 | | | |
| 95 | +| 90 | 1550 | | | |
| 96 | +| 100 | 1543 | | | |
| 97 | + |
| 98 | +Values in between can be interpolated. |
| 99 | + |
| 100 | +Assumption is that the distance can be adjusted to other liquids |
| 101 | +by using right formula. |
| 102 | + |
| 103 | + |
| 104 | +### Warnings from datasheet |
| 105 | + |
| 106 | +1. Please make sure the Ultrasonic sensor probe unite perpendicular to the object( around 90°±5°) |
| 107 | +When the ultrasonic sensor measure the object. If the angle bigger than 90°±5°,the signal will lose. |
| 108 | +2. Please keep the sensor probe fixed for the test and do not hold it with your hand.That would affect |
| 109 | +the signal. |
| 110 | +3. The controller is not waterproof. Please do not submerge the controller in water. |
| 111 | +4. This sensor is calibrated based on underwater measurement scenarios. |
| 112 | +Cannot be use in air measurement scenarios. |
| 113 | + |
| 114 | + |
| 115 | +### Related |
| 116 | + |
| 117 | +Supplier |
| 118 | +- https://www.positive-inno.com - supplier of the US500 (US4000 and more). |
| 119 | +- https://positive-inno.com/wp-content/uploads/2026/04/US500-Manual.pdf - datasheet |
| 120 | +- https://positive-inno.com/wp-content/uploads/2026/04/US4000LSG-M20-TTL-Manual.pdf - datasheet |
| 121 | + |
| 122 | +Libraries: |
| 123 | +- https://github.com/RobTillaart/US500 - this library |
| 124 | +- https://github.com/RobTillaart/SRF05 - library for SRF05 distance sensor with temperature and humidity compensation. |
| 125 | +- https://www.tinytronics.nl/nl/sensoren/afstand/pono-us500-hx-onderwater-ultrasone-afstandssensor-uart-50cm |
| 126 | + |
| 127 | + |
| 128 | +### Tested |
| 129 | + |
| 130 | +TODO test with hardware. |
| 131 | + |
| 132 | + |
| 133 | +## Interface |
| 134 | + |
| 135 | +```cpp |
| 136 | +#include "US500.h" |
| 137 | +``` |
| 138 | + |
| 139 | +### Constructor |
| 140 | + |
| 141 | +- **US500(Stream \* str)** Typical Serial1 or Serial2. |
| 142 | +It is not known if software serial will work (not tested). |
| 143 | +- **uint16_t getAddress()** returns 0x0005. Convenience function. |
| 144 | + |
| 145 | + |
| 146 | +### Core |
| 147 | + |
| 148 | +If the functions return a value < 0, it is an error code. |
| 149 | + |
| 150 | +- **float getDistance()** returns the distance in cm (or error code). |
| 151 | +- **int setMaxDistance(uint16_t distance)** set the maximum range in 0.1 mm |
| 152 | +Must be between 1500 and 5000. |
| 153 | +returns 0 = false or 1 = true (or error code). |
| 154 | +- **float getTemperature()** returns the temperature in degrees Celsius. |
| 155 | +(or error code). |
| 156 | +The resolution is in steps of 0.1 degree, supports negative values. |
| 157 | +- **void startMeasurement()** idem. |
| 158 | +- **void stopMeasurement()** idem. |
| 159 | + |
| 160 | + |
| 161 | +### Error codes |
| 162 | + |
| 163 | +| name | value | |
| 164 | +|:----------------------|:-------:| |
| 165 | +| US500_CMD_ERROR | -1 | |
| 166 | +| US500_CRC_ERROR | -2 | |
| 167 | +| US500_TIMEOUT_ERROR | -3 | |
| 168 | + |
| 169 | + |
| 170 | +### Helper |
| 171 | + |
| 172 | +- **void flush()** if communication is out of sync, |
| 173 | +one can flush int input buffer. |
| 174 | + |
| 175 | + |
| 176 | +## Future |
| 177 | + |
| 178 | +#### Must |
| 179 | + |
| 180 | +- improve documentation |
| 181 | +- get hardware |
| 182 | +- test, test, test |
| 183 | + |
| 184 | +#### Should |
| 185 | + |
| 186 | +- support US4000 |
| 187 | +- improve error handling |
| 188 | +- add range check for setMaxDistance or constrain. |
| 189 | +- verify software serial works / not. |
| 190 | +- test temperature range (water is typical > 0). |
| 191 | +- do we need to compensate distance for temperature? |
| 192 | + or is this done in the factory / device. |
| 193 | +- time for measurement after start. |
| 194 | +- performance indication. per function. |
| 195 | + |
| 196 | +#### Could |
| 197 | + |
| 198 | +- create unit tests if possible |
| 199 | + |
| 200 | +#### Wont |
| 201 | + |
| 202 | + |
| 203 | +## Support |
| 204 | + |
| 205 | +If you appreciate my libraries, you can support the development and maintenance. |
| 206 | +Improve the quality of the libraries by providing issues and Pull Requests, or |
| 207 | +donate through PayPal or GitHub sponsors. |
| 208 | + |
| 209 | +Thank you, |
| 210 | + |
| 211 | + |
0 commit comments