Design a gadget
Build guides › Water tank level sensor

How to build a water tank level sensor

A time-of-flight sensor that measures the water level in a tank and shows it on a screen.

Parts3 modules
SolderingThrough-hole headers only
FirmwareESPHome
Works withHome Assistant

Start buildingSee the board

You will need

Steps

  1. Order the parts

    PartWhyBuy
    ESP32-C3 SuperMiniThe brain: Wi-Fi, Bluetooth, USB-CAmazoneBay
    VL53L0X distance sensorPicked because the wish says “distance”AmazoneBay
    0.96 in OLED display (SSD1306)Picked because the wish says “screen”AmazoneBay
    Female pin headers, 2.54 mmSo every module plugs in and can be swappedAmazoneBay
    M3 × 6 mm self-tapping screws (4)Hold the board on the case standoffsAmazoneBay
  2. Order the circuit board

    Download the Gerbers and upload the zip to any board maker. Use the defaults: 2 layers, 1.6 mm, HASL. Five boards usually cost about the same as one. Compare fab prices.

    Gerbers (.zip)Order at PCBWay ($5 off a first order)

    The board is 71 × 68 mm.

  3. Print the case

    Print the tray and lid flat, no supports: PLA for indoors, PETG or ASA for outdoors, sheds or anything warm. 0.2 mm layers and 3 walls are plenty. The case is 78 × 75 × 34 mm and uses about 42.9 cm³ of plastic.

    Tray (.stl)Lid (.stl)

  4. Print the extras

    Optional printed parts that suit this build. Each opens in a customizer, already sized where it can be.

  5. Solder the headers

    Solder female headers into every module footprint on the board, so the modules plug in. Solder one pin, check the header sits flat, then do the rest. Each header has its pin order printed beside it.

    Before plugging anything in, compare each module's printed pin order with the board's silkscreen. Clone modules sometimes swap VCC and GND.
  6. Fit the modules

    • VL53L0X distance sensor: Aim it straight at the target through the window. Its range is about 2 m; beyond that use a bigger sensor.
    • 0.96 in OLED display (SSD1306): The OLED sits in the lid cut-out. Peel the screen protector off first.
  7. Flash the firmware

    Plug the ESP32-C3 into your computer. In the ESPHome dashboard (Home Assistant add-on) choose New device, paste the YAML below, and install over USB. The first install must be USB; after that updates go over Wi-Fi.

    Your Wi-Fi name and password go in ESPHome's secrets.yaml as wifi_ssid and wifi_password.

    # Generated by Circuit Wish. Flash with ESPHome (esphome.io): esphome run water-tank-level-sensor.yaml
    esphome:
      name: water-tank-level-sensor
    
    esp32:
      board: esp32-c3-devkitm-1
      framework:
        type: esp-idf
    
    logger:
    api:
    ota:
      - platform: esphome
    wifi:
      ssid: !secret wifi_ssid
      password: !secret wifi_password
      ap:
        ssid: "water-tank-level-sensor setup"
    captive_portal:
    
    i2c:
      sda: GPIO6
      scl: GPIO7
    
    sensor:
      - platform: vl53l0x
        name: "Water tank level sensor Distance"
        long_range: true
    
    font:
      - file: "gfonts://Roboto"
        id: big
        size: 20
    
    display:
      - platform: ssd1306_i2c
        model: "SSD1306 128x64"
        address: 0x3C
        lambda: |-
          it.print(0, 0, id(big), "Water tank l");
          // add "id: reading" to a sensor above, then: it.printf(0, 30, id(big), "%.0f", id(reading).state);
    

    Firmware (.yaml)

  8. Add it to Home Assistant

    Home Assistant finds the device on its own: go to Settings → Devices & services and press Configure on the ESPHome device it discovered. Every sensor appears as an entity.

    Ideas for automations:

    • Convert distance to a percentage with a template sensor and alert when low.
    • Change the display text from a Home Assistant text entity.
  9. Test it

    • VL53L0X distance sensor: Move your hand toward it: the distance in Home Assistant should follow within a second.
    • 0.96 in OLED display: After flashing, the gadget name should appear on the screen.

    Then screw the board into the tray with the four M3 screws and press the lid on.

If something is wrong

VL53L0X distance sensor

Jumpy readings on shiny water: add a median filter in ESPHome, or float a matt disc on the surface.

0.96 in OLED display

Blank screen: some modules swap GND and VCC on the header. Compare the printed pin order with the silkscreen before soldering.

ESP32-C3 will not flash

No serial port: hold BOOT while plugging in USB to force download mode.

Want something slightly different?

Describe it in a sentence. Circuit Wish picks the parts, writes the firmware, routes the board and sizes the case.

Design a gadget