Introduction: Advanced Water Management (AWM) in 10 Steps

About: Software engineer in electromobility

If 100 people lived on Earth, 74 had drinking water available when needed and free of contamination. (source: who). With this instructable, slightly more.

The equipment presented here permanently monitors and controls the water supply for a community of 7 houses. Hang around, I'll explain everything.

For five decades a small community in eastern Europe, in northern Romania, is dependent on a natural uphill spring water source; since the harmony with nature is declining ever since, a second source of water has been found - a well, which however requires an additional pump that fills the main supply tank.

The constant monitoring and pump control, which so far were done manually, is now automatic. This is a massive improvement, since monitoring the water level is critical for two reasons:

  • It is highly inconvenient to remain out of the blue without running water
  • Since an empty tank means air in the water lines, purging the system takes days to function again fully normally

An in-depth analysis of the equipment will be done in the step "Architecture".

Supplies

Equipment:

  • PC with Atmel Studio for C-code and UltimakerCura for 3D printing preparation
  • 3D printer (I use Creality Ender - Aliexpress)
  • Screwdrivers, pliers
  • Soldering gun
  • patience, coffee or tee

Components: I bought most of the parts on Ebay Germany, but for an international reach I was looking up the same components on Aliexpress.

So there you go:

  1. PCB: 1 for Master, 1 for Slave - see step "Circuitry and PCB Ordering / Preparation"
  2. Arduino nano: 2x (Aliexpress)
  3. Charging module TP4056: 1x (Aliexpress)
  4. Solar panel: 1x (Aliexpress)
  5. Radio module for master NRF24l01: 1x (Aliexpress)
  6. Radio module for slave NRF24L01+PA+LNA: 1x (Aliexpress)
  7. LCD display 20x4: 1x (Aliexpress)
  8. Ultrasonic sensor AJ-SR04M: 1x (Aliexpress)
  9. Boost converter MT3608: 1x (Aliexpress)
  10. Battery for Slave: I've used a 6000 mAh battery (65mm x 57mm x 9mm), which is much more than enough (without charging it lasts over 3 weeks of continuous operation). I've had it around and used it, but you can definitely use a smaller one - the solar panel is charging it all the time. Currently, I cannot find any identical one online.
  11. Resistors: 10kOhm, 100Ohm, 330Ohm, 220Ohm -> see Gerber files
  12. Capacitors: 100nF (4x), 10uF (7x), 100uF (2x) -> see Gerber files
  13. Linear voltage regulators: 1xLD1117v50 (Aliexpress) and 2xLD1117v33 (Aliexpress). At the time of order, I didn't find any LD1117v50 that comes within a reasonable amount of time, so I adapted an AMS1117 instead (Aliexpress).
  14. Diode 1N4148: 1x (Aliexpress)
  15. Connectors on PCB: JST PH cable: 2x (ebay)
  16. LEDs (1 x red, 1 x green and 1 x RGB); since the RGB is intended only for initialization status/diagnostics, I used a simple LED instead (Aliexpress).
  17. DC Jack Barrel 5.5x2.1 mm for the power input (Aliexpress)
  18. Relay for pump switching: SONGLE PCB 5V: 1x (Aliexpress)
  19. Mini-switches: 2 pins - 3x (Aliexpress), 3 pins - 1x (Aliexpress)
  20. Transistors BS170: 2x (Aliexpress)
  21. Screw terminal blocks for connecting the switches to the PCB (Aliexpress)
  22. Screws for fixing the boards in the casings (I used locally found screws from DIY markets: M2.5x10) and screws for fixing together the casings: 3x10mm (ebay)
  23. Power supply for Master: 1x (Aliexpress). You basically can use any power supply with an output Jack terminal 5.5x2.1mm and a maximum voltage of 15V.
  24. (Optional) 16mm in diameter flexible cable tube to protect the sensor cable (Aliexpress)

Step 1: Presentation of Main Components

In the following lines, I'll go through the main components, their functions and why I've chosen them.

  1. Arduino nano is the brain of the devices, with an ATmega 328p processor. It was chosen because of space considerations, enough I/O ports and low price.
  2. LCD 2004 is used for displaying the current information; it is programmed in 4-bit configuration (not over I2C!). It is perfect for this application, the backlight can be switched on/off with a switch, to avoid unnecessary power consumption and light pollution when not needed - don't forget the device is running around the clock - day and night.
  3. AJ-SR04M is a waterproof ultrasonic sensor which measures distances. It is compatible with HC-SR04 sensor in terms of pinning and software, however the AJ withstands humidity and connects to the main board over a 2m long cable, important requirements for the current project. The sensor sends a burst of ultrasonic waves and using interrupts in Arduino, the time duration until the signal comes back is measured. Given the speed of sound in air, the distance is easily calculated.

  4. NRF24L01 is used for Master as the receiver. It is a very good and non-expensive solution for radio communication. It is running with 3.3V, however the pins are 5V resistant.
  5. NRF24L01 + PA + LNA is used for Slave as the transmitter. Unlike the NRF24L01, this component possesses an antenna that enables communication ranges of over 1 km, the main reason for usage over the standard version. It is running with 3.3V, however the pins are 5V resistant. NRF24L01 and NRF24L01+PA+LNA are interchangeable, no modifications in circuitry or software are needed
  6. SONGLE relay is used to power the water pump. It is controlled by 5V over a transistor and not directly over Arduino pins (higher current needed than what Arduino pins can deliver) and can control an output of 250V AC and 10A, enough for pump specifications.
  7. Boost converter MT3608 is used only in Slave to supply a constant input voltage of 5V. The battery voltage varies between 3V (empty) and 4.2V (full), hence the need to increase the voltage to a constant 5V. The module offers a variable output voltage, so using a screwdriver turn the screw until the 5V voltage output is set.
  8. Charging module TP4056 is used only in Slave to charge the battery over a solar panel or micro-USB. The charging will be by default over the solar panel. It is a very effective module that delivers up to 1000mA current and has overcharging protection. Normally you're not allowed to run the Slave while charging (the module cannot then calculate the charging current) but since the Slave consumes such low power, I've tested it and it's fine. The red LED indicates charging, while the blue one that charging is complete.

Step 2: Architecture

The idea of the Advanced Water Management project has crystallized around a master-slave architecture, connected by radio communication.

The Slave

Its main purpose is to measure the water level in the tank and communicate it to Master.

It runs on a battery which is charged permanently by a solar panel, therefore as long as the sun is shining, it is completely autonomous. A function inside permanently monitors the battery state of charge and communicates it to the Master.

The measurements are communicated every 4 minutes, independent of whether the master listens or not. However, since it is synchronized with the Master (they go to sleep after a cycle always at the same time), the latter "scans" the air in the same interval as the Slave is sending.

Measuring the distance is done using a moisture-resistant ultrasonic sensor at the end of a 2m long cable. The sensor sits in its own casing and is mounted on top of the water tank. The other end of the cable is connected to the main board of the Slave.

The Master

The main purpose is to display the measurements from the Slave and control the water pump.

It uses an external 7-15V power supply and unlike the Slave which can be deployed anywhere on the field, the Master positioning is more limited, because it has to be around a power socket and the pump controlling power line.

It uses a 20x4 LCD display to show the water level and battery state communicated by Slave and other forecast/timing information.

When the water level is below a threshold (parameterizable - see step Software) the pump signal is set and remains on until a new threshold is reached (again, a parameter). There are three possibilities of pump control, using a 3 pin switch:

  • the pump is always off
  • the pump is automatic - the software decided when to turn on and off the pump
  • the pump is manual - the user can anytime switch the pump on

Status LEDs indicate when the water level is below the "empty" threshold or when the pump is running.

Step 3: Circuitry and PCB Ordering / Preparation

In total, we have two separate circuits, one for master and one for slave.

The schematics for both units are found below.

The Gerber files can be downloaded from here.

I've ordered the PCBs on PCBway, they came in a few days and work great!

Step 4: PCB Population

With PCBs arrived and all other components available, the boards can be assembled.

Don't solder the Arduino boards and the radio modules directly on the board, so that you have the possibility to remove/change them if necessary.

Programming the slave is not possible without removing the microcontroller, since the casing is in the way.

Therefore please use strips soldered on the board, see pictures ;).

Step 5: Software: Development and Calibration

Software development

For software development I used Atmel Studio 7 and the complete project is written in C language.

Why C? Well, I'm more familiar with it since it is still actual in the automotive industry (I am an automotive software engineer).

I was able therefore to create a clear and modular software architecture, one of my original purposes. Consequently, the different modules: LCD display, radio communication, ultrasonic sensor etc. can be easily copied and used in other projects.

Complete SW can be found on Github.

Parameters

This project is developed for a specific application, a concrete tank with specific measurements. In order to be able to transfer it to other projects, I've created a separate file (Parameteres.h) which summarizes all parameters used.

Parameters:

  • distance from the sensor to max tank level
  • distance from the sensor to min tank level
  • threshold considered as "tank empty", at which point the pump starts
  • threshold considered as "tank full" at which point the pump stops

Step 6: Power Management

The energy in the battery is limited and without a new influx of energy, sooner or later it will deplete. The influx of energy is ensured by the solar panel, but the "sooner or later" can be influenced in a great measure.

Indeed, the Slave is affected by this concern and I went in two directions:

  • Reduce the Arduino board consumption by putting it to sleep when not needed - I found a great post from Donal Morrissey regarding this.
  • Removed unnecessary consumers on the Arduino board - such as LEDs and the linear voltage regulator.

The library PowerManagement.c contains the functionality of putting the microprocessor in deep sleep mode.

Step 7: Compiling Software and Arduino Flashing

When the software is complete and all parameters set, you need to compile it and transfer it to the board.

Building software is from the menu Build -> Build Solution

To flash the board, you need to have the External Tools set. You find it under Tools -> External Tools...

How to set them correctly can be found in the following tutorial.

The port can be found in Device Manager, see image.

Step 8: CAD: Design, Slice, Print

The design of the casings was a highly time-consuming effort since everything had to come together perfectly.

I've used Solidworks for design and UltimakerCura for 3D printing preparation (slicing).

As for 3D printing, I've used the standard setup recommended by the tool.

You can download the 3D parts from here.

Step 9: Assemble Components

With the complete boards and available casings, the last step is to marry them. I find it the most rewarding step, as everything comes together and finally looks like complete devices!

Step 10: Connection of the Pump and Field Operation

The last step is to set the equipment in place and connect the water pump (the pump in the schematic is only an example, it is not the used part). The design offers the possibility of a nomally-open and normally-closed circuit for the pump circuitry. We'll use the normally-open (lower 2 pins in the connector, see image), since without any intervention the pump is by default off.

Please be aware that the relay can handle a max. voltage of 250V and max. current of 10A!

As mentioned in previous steps, with the lower 3 pole switch you can set the pump into automatic (software controls when to switch it on or off - position I) or control it manually (position II). With the switch in neutral, the pump is permanently off.

The Slave was fixed on the nearby wooden cabin and the sensor cable was protected with a flexible tube. The sensor itself was placed on the tank cover, over a hole that permits the measurements. How you fix the sensor on the cover is up to you, you can even screw it down.

/**********************************************************************************************************************/

And that was it! The Advanced Water Management is now complete.

If you managed to follow me till the end, congratulations! For me, it was great fun to accomplish it, even though the effort was not little. I would be very happy to see someone else doing it and therefore improving his / her or someone else's life.

If you found any bugs/problems or have any suggestions, feel free to leave them in the comments.

Many thanks,

Ovidiu

Electronics Contest

Second Prize in the
Electronics Contest