Water level lora sensor

Detect liquid level using a float to rotate battery powered device with accelerometer to detect inclination, send data using LoRaWAN radio

Similar projects worth following
The project aim is to monitor the water level of rivers, lakes or other outside waterways and send the data to a central server for display and action. Price and component availabilty are key constraints, as was the abilty to operate for months on a battery.

To detect the water level (without adding an extra water pressure or surface level sensor) the project concept is to use a simple 3-axis accelerometer, via mechanical setup that changes the orientation of the unit in relation to the water level.

The resulting sensor is based on available (cancelled product!) lorawan enabled STM32 cards which already had:
- the MCU (STM32L151) and solid open source firmware in C
- a LoRa radio (SX1272) and PCB antenna
- some on-board sensors (air temp/pressure, 3-axis acceleromere, light, sound)
- a IP67 case that can take the card and a LiSoCL2 battery


The project uses an existing board, which has the MCU, LoRaWAN radio and an accelerometer. It was designed for low power operation, and can run in a 'standby' mode at <20uA whilest keeping RAM contents.

 - MCU : STM32L151CCU6

 - radio Lora using SX1272, PCB antenna (+8dbm)

 - accelero ST LIS2DE12

 - altimeter (temp+pression) ST LPS22HB

 - microphone I2S : Knowles SPH0641LM4H-1

 - light sensor : phototransistor KPS-3227SO1C

 - MOSFET drive output PWM pour speaker

 - 2 LEDs (one red, one green)

 - GPIO (eg for button)

 - 2x 2mm header connector mounting points for UART and I2C (GROVE type connector footprints)

 -  header 2 pin for  2.4-3.6V DC (no LDO)

I used the EVE LiSOCl2 3.6V AA sized battery with  flying lead/2 pin header to power the board, and packaged it in the case that was created for the product (injection moulded 2 part case with incorporated silicon seal - supposedly ok for IP67) and the mounting bracket that goes with it (see the photos)


The principle is to make the device's inclination depend on the water level, and determine the inclination using the accelero. 2 ways of doing this were envisaged:

Option 1 : rotation by pulley

The device is mounted on a spindle, rotated by gearing from a pulley with a cord with a weight on each end. One of the weights is slightly heavier, and has a float attached. Both weights are in the water - the slightly heavier one should stay at the surface level due to the float... Water level change moves the float, leading to the cord rotating the pulley and hence rotating the device who's inclination is read using the accelero... 

Advantage is that the device can be far above the water and the mechanism requires limited space. 

Disadvantage is the cord/pulley/gearing mechanism is quite complex, will get wet (from water on the cord) and potentially corrode/block.

Option 2 : rotation by arm

The device is mounted on an arm, fixed to a hinge on a post on one end and with a float on the other. As the float moves up and down, the arm rotates up and down round the hinge and changes inclination.  

Advantage is the simplicity of the mechanism, the disadvantage is that high water levels may submerge the device...

Currently only the 2nd option has been tested.


The firmware for the device is based on existing project code which was already open sourced on github by the company that developed the initial versions (Wyres). This firmware is based on the Apache MyNewt RTOS, with enhancements to get a good low power operation on the STM32L151. All the source is on github.

An 'application' level code runs the device as a 'io control' unit, with a config to send readings every 15 minutes over LoRaWAN in a binary TLV formatted packet. 

Setting up the LoRaWAN network requires just configuring the device on your choice of LNS (I use TheThingsNetwork - TTN - as its easy and free) and ensuring you have a lorawan fgateway in range...

The firmware allows for a UART to be connected with a basic console (at reboot) for config, and log output.


A server side project  defines a docker set with:

- a python script running an MQTT client to receive data from the LoRaWAN TTN cloud, and decode/transform the values into a water depth value 

 - influxDB to hold the sensor data

- grafana server to display the data

To setup your own project, you should just need to deploy this docker set to any docker host and configure the TTN MQTT details to subscribe to your own TTN project.

  • 1 × W_BASEv2 Lora card and case (
  • 1 × Empty orangina bottle (other bottles may be substituted)
  • 1 × Scrap metal bar, bolts etc

  • 1
    build the firmware

    Follow the instructions in the github project to clone the projects to your PC.

    Build the firmware using the "hex_maker.bat" script (Windows 10 PC) and the target 'mynewt_wbasev2_eu868_river_dev'. This should create a 'built/wbasev2_io_eu868_river_dev.hex' file.

  • 2
    build the config

    Using the command line tool in the project (flash_config.bat) create the config with a LoRa devEUI and appKey. Note you need to have java7 or later available on the PC as the tool uses a java app to create the binary file. This should create a file called 'config_<devEUI>.hex'

  • 3
    configure the lorawan LNS

    You can use any LoRaWAN 1.0.2 compatible LNS / gateways - I used TTN with an existing local gw. Depending on the LNS used, the config method will vary, but generally you must add the device with the devEUI, its secret appKey, and the correct version (1.0.2) and region (eu868).

View all 8 instructions

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates