Fig .: DS1603L ultrasonic level sensor with serial data output
The ultrasonic sensor records liquid levels in a tank and sends NMEA0183 telegrams to the on-board network via WLAN. These can then be visualized in, for example, AVnav or OpenCPN. Due to the properties of the sensor, no hole needs to be drilled into the tank, so this sensor is ideal as a retrofit solution for existing tanks without a level indicator. Thanks to the WFirmwareLAN connection, no further data cables have to be laid, a 12V supply near the tank to which the microcontroller can be connected is sufficient. The Wemos D1 mini module is a microcontroller based on the ESP 8266 with a built-in WLAN module. The ultrasonic sensor is connected to the microcontroller via a serial interface. The ultrasonic sensor is glued to the outside of the tank bottom. The liquid level in the tank can then be recorded with this.
Caution: The sensor must be attached to the bottom of the tank and have contact with the liquid. This causes the sound to be transmitted into the liquid. So it has to “ping” from bottom to top in order to record the liquid level. "Ping" from top to bottom via the airway does not work. It has been found that pressing the ultrasonic sensor against the tank is not sufficient to transmit the sound into the liquid. You need contact gel or stick the sensor to the bottom of the tank. For test purposes, hand cream or grease can be used as a substitute for contact gel.
Ultrasonic sensor DS1603L
The ultrasonic sensor DS1603 is available in different versions. We use the version with a serial output, marked with the L at the end. The sensor has the following properties:
characteristics
- Operating voltage: 3.3-12V DC
- Power Consumption: <35mA
- Blind Area: <= 50mm
- Measuring range: 50…2000 mm
- Output: UART RS232 serial 9600 8N1 (TX only)
- Resolution: 1mm
- Response time with liquid: 2s
- Response time without liquid: 10s
- Measurement accuracy: ± (3 + H x 0.5 %) mm
- ESD Resistance: ±4/±8KV
data output
- 9600 Bd, 8 data bits, one stop bit, no parity bit (8N1).
- 4 bytes of data:
- Byte1 header: fixed value 0xFF
- Byte2 Data_H: high byte of height.
- Byte2 Data_L: low byte of height.
- Byte4 checksum
checksum: Checksum = (Header + Data_H + Data_L) & 0x00FF
Calculation of the filling level: Height [mm] = Data_H * 256 + Data_L
Meaning of the blue status LED
LED state | meaning |
permanently on | No sound level found |
blinking | Ready to measure, sound level found |
At the beginning, the ultrasonic sensor tries to set the transmission level of the sound signal so that a measurement is possible. The sensor needs 10s for this. During this time, the LED is permanently on. As soon as a valid echo signal has been detected, the blue LED starts flashing at a rhythm of 2s. Each blink sends 4 bytes of data over the TX line. If a measurement is not possible, the LED stays on permanently and the checksum is incorrect. However, 4 bytes of data are still sent. The cause is often a lack of contact gel for sound transmission.
cable assignment
Cable color | meaning |
Red | 3.3-12VDC |
Black | GND |
Yellow | TX * |
White | RX * |
* Voltage level dependent on supply voltage (4V at 5V supply voltage)
curve
Fig. Sensor characteristic 0…90 mm at 5V supply voltage
Depending on the supply voltage, the ultrasonic sensor starts measuring at a liquid level of 30 mm. At 25 mm, however, an erroneous reading occasionally occurs, which is given as a liquid height of 60 mm. You should therefore not trust the measured values below 40...50 mm. Below 20 mm, no valid measurement signals are transmitted and the checksum is incorrect. The status LED is permanently on. The specification also shows a dead zone of 0…50 mm.
measurement accuracy and linearity
Fig. Linearity of the DS1603 in the valid measuring range 30…90 mm
The measurement accuracy is sufficiently accurate for a fill level measurement. The offset error on my model is about 4 mm. The slope is not exactly at 1.0. The measured values could be improved with an offset and slope correction.
Overall, however, when measuring the level in a tank, it must be remembered that there is a dead zone of 0...50 mm. The tank must have a certain height in order to be able to calculate the filling level with any degree of accuracy. The tank should have a minimum height of 250mm and be square. The liquid column above the sensor is measured with the ultrasonic measuring method. The tank level is specified as a percentage of the maximum level. If the tank geometry deviates from the cuboid shape, the output value does not correspond to the fill level in percent.
Data transfer
The Wemos is connected to the on-board network via the WLAN module. For this purpose, a setup page is called up when starting for the first time or whenever there is no known WLAN network. If the microcontroller is connected to the network and the sensor has detected a liquid level in the tank, the corresponding NMEA data records are sent to the on-board network via UDP as broadcast transmissions. The configuration page closes automatically if the sensor was able to log into the on-board WiFi or automatically after 10 minutes.
parameter | value |
SSID | Ultrasonic Sensor |
password | 12345678 |
transmission type | WiFi 2.4GHz, 802.11bgn |
transmission type | UPD, Broadcast |
port | 50000 |
Fig. Transmission parameters
Fig. Configuration page
circuit design
The circuit structure is quite simple. Only a few components and cable connections are required.
Fig. Ultrasonic sensor circuit
The following parts are required for the ultrasonic sensor:
position | number | designation | source | comment |
1 | 1 | Wemos D1 mini | Makershop.de | |
2 | 1 | Wemos 7-24V 1A DC Power Shield | Makershop.de | |
3 | 1 | Resistor 1k, 1/4W | Pollin.de | |
4 | 1 | Resistor 2k2, 1/4W | Pollin.de | |
5 | 1 | stranded wire | Pollin.de | optional |
6 | 1 | shrink tubing | Pollin.de | optional |
7 | 1 | casing | Pollin.de |
The ultrasonic sensor is soldered to the respective pins of the Wemos D1 mini and then plugged onto the power shield. Everything is then housed in a waterproof case.
Programming the firmware
The firmware is programmed using a micro USB cable, which is connected to the Wemos D1 mini and the PC. The programming then runs according to the following instructions:
Programming instructions
- Build the programming circuit together
- Connect PRG and GND
- Connect the USB programming adapter to the laptop or PC
- Connect the 9V battery block
- Programming software NodeMCU Flasher start on laptop or PC and Firmware load
- Start the programming process
- If programming is successful, disconnect USB and switch off 9V
- Separate PRG and GND
- Disconnect the programming circuit from the circuit board
- Switch on 12V and check firmware via WiFi connection
NodeMCU Flasher
The easy-to-use Windows tool NodeMCU Flasher be used. The EXE file can be started directly without any special installation. The tool can be used for both external and in-circuit programming. The first thing to do is take Advanced made the following settings. If you use a Wemos D1 mni Pro, you have to set the flash size to 16MB.
After that, under Config the current firmware file firmware.bin selected.
You open up to flash surgery and selects the corresponding interface to which the adapter is connected. Then you press Flash and wait until the firmware is loaded.
The progress of the transfer is displayed during the flashing.
If the firmware has been successfully loaded, the following screen will appear.
After the transfer, the programming tool can be closed and the adapter removed.
Integration with AVnav
Integration with OpenCPN
_________________________________________________
The idea of the level sensor was created in the sailing forum by several sailors. Andreas built a prototype and tested it on various objects. By using commercially available ready-made modules (Wemos D1 mini pro, 24V shield), a simple replica is possible. The software can be flashed into the Wemos D1 via the USB interface. The sensor is to be attached to the tank in the boat soon.
https://www.segeln-forum.de/thread/76476-ber%C3%BChrungsloses-messen-von-tankinhalten/?pageNo=1
A detailed description of the project can be found here: