Skip to content

This project uses an ESP8266 on battery to measure the water level in a tank an reports it to a MQTT server over Wifi. It is meant to work on battery but can be used on USB power.

License

Notifications You must be signed in to change notification settings

csu333/waterLevel

Repository files navigation

Water Level Sensor

This project uses an ESP8266 on battery to measure the water level in a tank an reports it to a MQTT server over Wifi. It is meant to work on battery but can be used on USB power.

Hardware

  • Lilygo T-OI (it should work with other ESP8266-based boards but it has not been tested)
  • Ultra Sonic module AJ-SR04M (for example here).

Optional:

  • A 16340 battery
  • Wifi antenna

The sensor should be placed in the tank where it will not pick up a reading from other obstacle so mind the reading radius

Preparation and building

In this application, the distance sensor is used in Mode 4 (Low Power Serial Port Mode), so a 47 kΩ resistor must be soldered on R19.

Rename config.h.sample to config.h and adapt the settings to your environment.

Use Arduino IDE to buil and deploy. Make sure you have the following libraries:

  • WiFi (by Arduino)
  • ArduinoJson (by Benoit Blanchon)
  • ArduinoLog (by Thijs Elenbaas)
  • PubSubClient (by Nick O'Leary)

Add a Board Manager URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json

Select board Generic ESP8266 Module under Tools > ESP8266 Boards

To deploy, set Flash mode to DOUT.

Software configuration

The software is configured over MQTT. You need to send a JSON message to the device on topic ROOT_TOPIC/config with configuration values. The possible settings are (case-sensitive):

  • minValue (Default 200mm): the value read when there is no water in the tank. The sensor has a blind area of 20cm so the default value is as low has it can get. This ensures that the correct value is detected as the level in the tnak changes.
  • maxValue (Default 8000mm): the value read when the tank is full. The sensor cannot measure distamces of more than 8m.This ensures that the correct value is detected as the level in the tnak changes.
  • sleepTime (Default 300s): the time between 2 readings in seconds (max. 4260 because of hardware limitations). This setting has a huge impact on autonomy.
  • maxDifference (Default 200mm): the maximum difference allowed between 2 readings. If the difference is higher, another reading is performed.
  • logLevel (Default 3): a value between 0 and 6 to define how much is logged.

Example:

{
  "minLevel": 400,
  "maxDifference": 15
}

If you configure more than one probe, you can use indexed minLevel and maxLevel:

{
  "minLevel[0]": 1000,
  "maxLevel[0]": 300,
  "maxLevel[1]": 250
}

Mind the quotes, punctuation and casing!

Make sure you send the config with the Retain option. The values are read at the end of the reading cycle so it will take up to 5 minutes for the settings to apply. To speed up the process, you can push the reset button to trigger a new cycle.

Remote update (buggy)

You can update the firmware remotely by sending the url of the firmware on topic ROOT_TOPIC/update/url. Only works in http port 80.

Hardware setup

This is how you connect your ESP8266: Probe connections

Sensor installation

About

This project uses an ESP8266 on battery to measure the water level in a tank an reports it to a MQTT server over Wifi. It is meant to work on battery but can be used on USB power.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages