---
title: Measuring rain water tank level with an Arduino
canonical: https://0110.be/posts/Measuring_rain_water_tank_level_with_an_Arduino
markdown_url: https://0110.be/posts/Measuring_rain_water_tank_level_with_an_Arduino.md
id: 543
published_at: '2024-03-28T00:00:00Z'
updated_at: '2024-03-29T10:47:07Z'
author: Joren
tags:
- name: UGent
  markdown_url: https://0110.be/tags/UGent.md
---

# Measuring rain water tank level with an Arduino

<div style="float:right;width:35%;max-width:300px;margin-left:10px;margin-bottom:10px;">
<center>
<img loading="lazy" style="width:100%"  src="https://0110.be/files/attachments/543/Diagram_zonder_titel.drawio.svg" ><br>
</center>
<small>Fig: Submersible water level meter.</small>
</div>

Due to the climate crisis, long droughts are becoming more common in Western Europe during the summers. Conversely, during the winters, it seems that there is more and more extreme rainfall. With [record breaking](https://www.meteo.be/nl/klimaat/klimaat-van-belgie/klimatologisch-overzicht/2024/februari) droughts and rainfall, it is essential that enough rainwater buffering capacity is available. As a private citizen this means installing a large rain water tank - perhaps larger than outdated models suggest - and using the captured water effectively, if at all possible.

<div style="float:left;width:15%;max-width:300px;margin-right:10px;margin-bottom:10px;">
<center>
<img loading="lazy" style="width:100%"  src="https://0110.be/files/attachments/543/submersible-water-level-sensor.jpg" ><br>
</center>
<small>Fig: Submersible water level meter.</small>
</div>

To effectively use rain-water, it helps to have an easy way to view the water level in the tank. This makes clear when to conserve water or when a pump might end up running dry and overheat. So I wanted to install **a water level measurement device in my rain water tank**.

My first attempt used sonar. This sends out a sound-wave which reflects on the water surface. The sonar measures the time it takes for the echo to return. This setup is finicky in an echoy tank but I managed to get it working. However, after couple of months the sonar stopped working in the damp environment.

Next I tried a optical, infra-red-based setup: the idea was to time the infra-red reflection on the water. After installation it appeared that water is transparent for infra-red. I basically measured the position of the floor of my tank. I took comfort in the fact that this measurement remained stable but had to look for a third option.

I finally became aware of sturdy, submersible pressure sensors which are designed for water level measurements. One of those is the QDY30A sensor, which is available in many versions but there is one which takes five volts as input and returns a 0 - 3.3V output: ideal to use with about any modern micro-controller. The sensor can be connected via a long cable. This helps to keep the Arduino in a dry place indoors. After recording a few measurements and the corresponding sensor depth, the sensor seems to show a very linear response: with two references, converting a sensor value to a depth in millimeters is doable. The readings ended up on a website and are [visualized via a SVG sparkline](https://alexplescan.com/posts/2023/07/08/easy-svg-sparklines/).

<center>
<svg height="70px" style="width:80%" viewBox="0 183.46000000000004 432 475.0" preserveAspectRatio="none">
  <path d="M 
        0 185.2199999999998 L
        1 186.0999999999999 L
        2 186.0999999999999 L
        3 183.46000000000004 L
        4 185.2199999999998 L
        5 185.2199999999998 L
        6 186.98999999999978 L
        7 186.98999999999978 L
        8 186.98999999999978 L
        9 190.51000000000022 L
        10 190.51000000000022 L
        11 200.19999999999982 L
        12 200.19999999999982 L
        13 220.46000000000004 L
        14 226.6199999999999 L
        15 225.73999999999978 L
        16 227.5 L
        17 228.3800000000001 L
        18 228.3800000000001 L
        19 232.78999999999996 L
        20 231.90999999999985 L
        21 236.30999999999995 L
        22 236.30999999999995 L
        23 237.19000000000005 L
        24 239.82999999999993 L
        25 240.71000000000004 L
        26 245.1199999999999 L
        27 246.0 L
        28 250.4000000000001 L
        29 254.80999999999995 L
        30 268.02 L
        31 301.4899999999998 L
        32 307.6500000000001 L
        33 310.3000000000002 L
        34 308.5300000000002 L
        35 308.5300000000002 L
        36 305.0100000000002 L
        37 305.0100000000002 L
        38 305.8899999999999 L
        39 304.1300000000001 L
        40 309.4200000000001 L
        41 308.5300000000002 L
        42 312.94000000000005 L
        43 312.94000000000005 L
        44 312.05999999999995 L
        45 312.05999999999995 L
        46 311.17999999999984 L
        47 312.94000000000005 L
        48 324.3899999999999 L
        49 312.94000000000005 L
        50 312.94000000000005 L
        51 314.6999999999998 L
        52 380.76 L
        53 389.56999999999994 L
        54 389.56999999999994 L
        55 389.56999999999994 L
        56 394.8499999999999 L
        57 397.49 L
        58 397.49 L
        59 397.49 L
        60 413.3499999999999 L
        61 423.03999999999996 L
        62 421.28 L
        63 422.1600000000001 L
        64 423.9200000000001 L
        65 424.79999999999995 L
        66 423.9200000000001 L
        67 421.28 L
        68 423.9200000000001 L
        69 425.68000000000006 L
        70 428.31999999999994 L
        71 425.68000000000006 L
        72 430.0799999999999 L
        73 430.0799999999999 L
        74 430.0799999999999 L
        75 425.68000000000006 L
        76 430.0799999999999 L
        77 434.49 L
        78 437.1300000000001 L
        79 438.01 L
        80 438.8900000000001 L
        81 437.1300000000001 L
        82 443.29999999999995 L
        83 439.77 L
        84 439.77 L
        85 439.77 L
        86 439.77 L
        87 437.1300000000001 L
        88 438.01 L
        89 435.3699999999999 L
        90 440.6500000000001 L
        91 439.77 L
        92 439.77 L
        93 442.4100000000001 L
        94 445.05999999999995 L
        95 442.4100000000001 L
        96 442.4100000000001 L
        97 442.4100000000001 L
        98 445.94000000000005 L
        99 444.18000000000006 L
        100 441.53 L
        101 441.53 L
        102 442.4100000000001 L
        103 444.18000000000006 L
        104 445.05999999999995 L
        105 445.94000000000005 L
        106 447.70000000000005 L
        107 449.46000000000004 L
        108 449.46000000000004 L
        109 451.22 L
        110 451.22 L
        111 449.46000000000004 L
        112 451.22 L
        113 447.70000000000005 L
        114 447.70000000000005 L
        115 447.70000000000005 L
        116 445.05999999999995 L
        117 444.18000000000006 L
        118 442.4100000000001 L
        119 442.4100000000001 L
        120 441.53 L
        121 440.6500000000001 L
        122 438.8900000000001 L
        123 439.77 L
        124 438.8900000000001 L
        125 437.1300000000001 L
        126 437.1300000000001 L
        127 439.77 L
        128 439.77 L
        129 445.05999999999995 L
        130 445.05999999999995 L
        131 444.18000000000006 L
        132 441.53 L
        133 442.4100000000001 L
        134 443.29999999999995 L
        135 444.18000000000006 L
        136 445.94000000000005 L
        137 441.53 L
        138 444.18000000000006 L
        139 447.70000000000005 L
        140 449.46000000000004 L
        141 459.1500000000001 L
        142 452.0999999999999 L
        143 452.0999999999999 L
        144 452.0999999999999 L
        145 468.8399999999999 L
        146 452.0999999999999 L
        147 449.46000000000004 L
        148 452.0999999999999 L
        149 452.98 L
        150 453.8599999999999 L
        151 452.98 L
        152 453.8599999999999 L
        153 452.0999999999999 L
        154 452.98 L
        155 452.98 L
        156 452.98 L
        157 456.51 L
        158 453.8599999999999 L
        159 454.75 L
        160 453.8599999999999 L
        161 455.6300000000001 L
        162 453.8599999999999 L
        163 453.8599999999999 L
        164 456.51 L
        165 456.51 L
        166 454.75 L
        167 453.8599999999999 L
        168 453.8599999999999 L
        169 453.8599999999999 L
        170 453.8599999999999 L
        171 451.22 L
        172 449.46000000000004 L
        173 451.22 L
        174 452.0999999999999 L
        175 452.98 L
        176 452.98 L
        177 451.22 L
        178 447.70000000000005 L
        179 467.96000000000004 L
        180 448.5799999999999 L
        181 447.70000000000005 L
        182 449.46000000000004 L
        183 447.70000000000005 L
        184 444.18000000000006 L
        185 448.5799999999999 L
        186 444.18000000000006 L
        187 444.18000000000006 L
        188 445.94000000000005 L
        189 452.0999999999999 L
        190 452.98 L
        191 452.0999999999999 L
        192 452.98 L
        193 452.98 L
        194 452.0999999999999 L
        195 452.0999999999999 L
        196 451.22 L
        197 453.8599999999999 L
        198 453.8599999999999 L
        199 453.8599999999999 L
        200 452.98 L
        201 449.46000000000004 L
        202 451.22 L
        203 445.05999999999995 L
        204 439.77 L
        205 430.0799999999999 L
        206 425.68000000000006 L
        207 423.9200000000001 L
        208 421.28 L
        209 411.5899999999999 L
        210 412.47 L
        211 411.5899999999999 L
        212 409.8299999999999 L
        213 414.23 L
        214 408.94000000000005 L
        215 407.18000000000006 L
        216 402.78 L
        217 403.6600000000001 L
        218 405.4200000000001 L
        219 402.78 L
        220 402.78 L
        221 400.1400000000001 L
        222 399.26 L
        223 405.4200000000001 L
        224 403.6600000000001 L
        225 402.78 L
        226 403.6600000000001 L
        227 408.94000000000005 L
        228 406.29999999999995 L
        229 409.8299999999999 L
        230 407.18000000000006 L
        231 416.8699999999999 L
        232 420.3900000000001 L
        233 419.51 L
        234 416.8699999999999 L
        235 417.75 L
        236 415.99 L
        237 434.49 L
        238 416.8699999999999 L
        239 425.68000000000006 L
        240 425.68000000000006 L
        241 440.6500000000001 L
        242 425.68000000000006 L
        243 438.01 L
        244 427.44000000000005 L
        245 429.20000000000005 L
        246 428.31999999999994 L
        247 434.49 L
        248 433.6099999999999 L
        249 439.77 L
        250 439.77 L
        251 439.77 L
        252 444.18000000000006 L
        253 439.77 L
        254 438.01 L
        255 439.77 L
        256 439.77 L
        257 438.8900000000001 L
        258 439.77 L
        259 431.8499999999999 L
        260 435.3699999999999 L
        261 433.6099999999999 L
        262 427.44000000000005 L
        263 430.0799999999999 L
        264 433.6099999999999 L
        265 433.6099999999999 L
        266 433.6099999999999 L
        267 435.3699999999999 L
        268 433.6099999999999 L
        269 433.6099999999999 L
        270 431.8499999999999 L
        271 437.1300000000001 L
        272 436.25 L
        273 435.3699999999999 L
        274 428.31999999999994 L
        275 430.0799999999999 L
        276 428.31999999999994 L
        277 438.01 L
        278 438.01 L
        279 437.1300000000001 L
        280 438.8900000000001 L
        281 438.8900000000001 L
        282 439.77 L
        283 438.8900000000001 L
        284 439.77 L
        285 442.4100000000001 L
        286 445.05999999999995 L
        287 448.5799999999999 L
        288 444.18000000000006 L
        289 443.29999999999995 L
        290 447.70000000000005 L
        291 450.3399999999999 L
        292 451.22 L
        293 452.0999999999999 L
        294 453.8599999999999 L
        295 452.98 L
        296 452.0999999999999 L
        297 451.22 L
        298 450.3399999999999 L
        299 453.8599999999999 L
        300 453.8599999999999 L
        301 456.51 L
        302 456.51 L
        303 456.51 L
        304 456.51 L
        305 458.27 L
        306 457.3900000000001 L
        307 460.9100000000001 L
        308 455.6300000000001 L
        309 460.03 L
        310 455.6300000000001 L
        311 456.51 L
        312 453.8599999999999 L
        313 453.8599999999999 L
        314 447.70000000000005 L
        315 449.46000000000004 L
        316 449.46000000000004 L
        317 448.5799999999999 L
        318 440.6500000000001 L
        319 445.05999999999995 L
        320 439.77 L
        321 434.49 L
        322 429.20000000000005 L
        323 424.79999999999995 L
        324 422.1600000000001 L
        325 416.8699999999999 L
        326 414.23 L
        327 410.71000000000004 L
        328 408.05999999999995 L
        329 400.1400000000001 L
        330 399.26 L
        331 401.9000000000001 L
        332 399.26 L
        333 424.79999999999995 L
        334 395.73 L
        335 391.3299999999999 L
        336 391.3299999999999 L
        337 388.69000000000005 L
        338 386.9200000000001 L
        339 385.1600000000001 L
        340 384.28 L
        341 405.4200000000001 L
        342 384.28 L
        343 382.52 L
        344 383.4000000000001 L
        345 382.52 L
        346 384.28 L
        347 383.4000000000001 L
        348 383.4000000000001 L
        349 381.6400000000001 L
        350 382.52 L
        351 383.4000000000001 L
        352 382.52 L
        353 383.4000000000001 L
        354 383.4000000000001 L
        355 382.52 L
        356 380.76 L
        357 383.4000000000001 L
        358 383.4000000000001 L
        359 380.76 L
        360 381.6400000000001 L
        361 381.6400000000001 L
        362 379.8800000000001 L
        363 384.28 L
        364 383.4000000000001 L
        365 383.4000000000001 L
        366 396.6099999999999 L
        367 439.77 L
        368 439.77 L
        369 462.6700000000001 L
        370 458.27 L
        371 466.20000000000005 L
        372 467.0799999999999 L
        373 472.3599999999999 L
        374 475.0 L
        375 473.24 L
        376 469.72 L
        377 465.31999999999994 L
        378 463.54999999999995 L
        379 466.20000000000005 L
        380 463.54999999999995 L
        381 461.78999999999996 L
        382 465.31999999999994 L
        383 463.54999999999995 L
        384 461.78999999999996 L
        385 458.27 L
        386 461.78999999999996 L
        387 461.78999999999996 L
        388 458.27 L
        389 461.78999999999996 L
        390 455.6300000000001 L
        391 456.51 L
        392 454.75 L
        393 453.8599999999999 L
        394 453.8599999999999 L
        395 453.8599999999999 L
        396 455.6300000000001 L
        397 453.8599999999999 L
        398 453.8599999999999 L
        399 453.8599999999999 L
        400 452.98 L
        401 452.0999999999999 L
        402 449.46000000000004 L
        403 448.5799999999999 L
        404 445.94000000000005 L
        405 449.46000000000004 L
        406 445.94000000000005 L
        407 444.18000000000006 L
        408 445.94000000000005 L
        409 445.05999999999995 L
        410 444.18000000000006 L
        411 442.4100000000001 L
        412 444.18000000000006 L
        413 440.6500000000001 L
        414 441.53 L
        415 449.46000000000004 L
        416 445.94000000000005 L
        417 445.05999999999995 L
        418 441.53 L
        419 443.29999999999995 L
        420 443.29999999999995 L
        421 442.4100000000001 L
        422 449.46000000000004 L
        423 445.94000000000005 L
        424 442.4100000000001 L
        425 442.4100000000001 L
        426 442.4100000000001 L
        427 456.51 L
        428 451.22 L
        429 463.54999999999995 L
        430 460.03 L
        431 450.3399999999999 L
        432 447.70000000000005 L
    " stroke-width="2" stroke="blue" fill="transparent" vector-effect="non-scaling-stroke"></path>
</svg><br/>
<small>Fig: Rain water level visualization for a few days, measured every 15 minutes. Going from 221cm to 197cm.</small>
</center>

With the Arduino code attached you should be able to get going. Next to reading and converting a sensor value, it also includes reading the median of several values to add some smoothing. The sensor is read on request: only when a serial message arrives a measurement is done.

