Bluetooth LE water leak detector

Water leak detectors with servos on taps costs not a lot. But not any room, where water cranes have placed in a home, has power and signal wires for water leak detectors. Here water leak detectors were equipped with Bluetooth LE beacons powered with batteries.

The main idea is that the Bluetooth transmitter will be powered only from the time the water leak has detected. Because of this, batteries might work for a long time. 

The Bluetooth transmitter will be working in iBeacon mode, then a home computer/controller may detect this signal and might power on servos for close all taps.

Mobirise


Bluetooth 4.0 module based on CC2541/2540 chip (HM-10) was used. There many counterfeit modules with this chip and this name are sold, but all of them may work in iBeacon mode.

Mobirise


USB to UART converter, being plugged to PC, was used in order for tune iBeacon mode in the Bluetooth module.

Mobirise

Any raindrop sensor may use, but the gold plated long life option is best.

Mobirise

Few manipulators (actuators) being placed on water taps and can be manipulated by the home computer or a controller.

Nrf52840


Here was used the Nordic nRF52840 bluetooth 4.0 LE module for the iBeacon detection and the water manipulators switching.

The USB to UART converter needs to be with two power pins on a board: + 5V and + 3.3V. The power selector (jamper) must be placed in 3.3V position. But VCC wire to the HM-10 Bluetooth module must be connected to the 5V pin of the USB to UART converter.

The other three wires between the HM-10 Bluetooth module and the USB to UART converter are: GND, Rx (crossvice to Tx) and Tx (crossvice to Rx).

Once the USB to UART module connected to the PC, in Windows Device Manager was found a new COM port and its parameters 9800,N,8,1 was tuned (but for some HM-10 modules, the parameters 115200,N,8,1 must be tuned).

Mobirise

This COM port was opened within the Arduino IDE.
Note: for some HM-10 modules, the "Both NL & CR" and 9600 parameters must be set within COM' port window of Arduino IDE, but for other ones, these parameters must be set to "No line ending" and 115200.

Then on site https://www.uuidgenerator.net/ was generated UUID, and on another site https://www.random.org/ were generated two random 5-digits strings, for use as iBeacon Major and Minor.

Then Huamao Config Assistant was downloaded.

Mobirise

On tab "iBeacon function for Slave Role" in HMConfigAssistant, were entered iBeacon UUID, Major, Minor.
Then the "Create iBeacon AT Commands List" button was pressed.

Mobirise

AT commands, generated with HMConfigAssistant...

Mobirise

... were sended to the HM-10 Bluetooth module via COM port one by one.
And next commands were entered additionally:
AT+ADVI5
AT+NAMEWLeak
AT+RESET

Where "WLeak" is the name of iBeacon module, "5" is advertising interval (near 540 msec).

Then the HM-10 Bluetooth module was disconnected to the PC.

Mobirise

From this moment, the HM-10 Bluetooth module is in iBeacon mode all time being powered on.

Mobirise

Next the Bluetooth iBeacon module was soldered to the raindrop sensor (S1 - S2 points) with this simple scheme.

Not only one HM-10 Bluetooth module can be tuned in this manner for work in the same house or flat. But UUID, iBeacon Major and Minor must be unique for each module.

Commands for switching on/off water manipulators, on the base of the water leak detector's data, can be performed by any computer. Here described the usage of Nordic nRF52840 bluetooth 4.0 LE module for the iBeacon detection and the water manipulators switching.

All settings were made via Windows PC (64 bit is preferred). This toolchain was installed on:

  • the MinGW was deployed in folder C:\MinGW. While installing under Basic Setup, were chosen packages mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++, msys-base. Then Installation.Apply Changes.Apply was approved.
  • to the Windows PATH environment variable was added substring C:\MinGW\bin;C:\MinGW\msys\1.0\bin.
  • the SDK archive (version 15.2.0_9412b96) for nRF52832 was extracted in the workspace named C:\Users\%username%\Documents\nRF5 in folder nRF5SDK15209412b96.
  • the GNU-ARM-GCC package was deployed with the checked on "Add path to environment variable" while installing. In that time the 8.2.1 version was installed.
  • as known bug of v.8 GNU-ARM-GCC package, file arm-none-eabi-objcopy.exe from C:\Program Files (x86)\GNU Tools ARM Embedded\8 2018-q4-major\bin folder was replaced on this one from GNU-ARM-GCC package v.6.
  • the Geany text editor was used for editing the source code of the Bluetooth Nordic nRF52840 module firmware. That editor can be deployed anyplace.

Then in to file C:\Users\%username%\Documents\nRF5\nRF5SDK15209412b96\components\toolchain\gcc\Makefile.windows
being opened in a text editor were updated strings ("/" here is right):

GNU_INSTALL_ROOT := C:/Program Files (x86)/GNU Tools ARM Embedded/8 2018-q4-major/bin/

GNU_VERSION := 8.2.1 

GNU_PREFIX := arm-none-eabi

Black Magic Probe (BMP) programmer was used for the software flashing of the Bluetooth Nordic nRF52840 module. The BMP programmer was connected to the PC via USB. Then Device Manager was opened on the PC:

Win+R

devmgmt.msc, Enter

In Device Manager in "Ports (COM & LPT)" topic was found "Black Magic GDB Server" device (this name is in Windows 7, but in Windows 10 here will be two "USB Serial Device", between them the device with minor COM-port number is sought for), and it's COM-port number was noted.

nrf 52840

The Black Magic Probe programmer was connected to Bluetooth Nordic nRF52840 module with Test Hooks Clips for Logic Analyzers with only four wires:

Black Magic Probe programmer pinnRF52840 BT module pin
TMS33 (SWDIO)
TCK32 (SWDCLK)
VCC 3.3V10 (VCC)
GND24 (GND)

Next steps were on the PC in order to flash Bluetooth Nordic nRF52840 module:

  • this set of files (being unzipped) was placed in folder: C:\Users\%username%\Documents\nRF5\nRF5SDK15209412b96\examples\ble_central\NRF52840-Beacon_Scanner
  • then in file main.c of this set was replaced two UUIDs of HM-10 BT devices (iBeacons) for detect a water leak in two places of the flat. The nRF52840 module will switch the water manipulators if any or both of this BT devices (iBeacons) will detected.
  • then file main.c was saved with no other modification within.

On the PC was opened the command-line terminal:

Win+R

cmd, Enter

Then in the PC command-line terminal were entered one by one:

mkdir c:\Users\%username%\temp

cd C:\Users\%username%\Documents\nRF5\nRF5SDK15209412b96\examples\ble_central\NRF52840-Beacon_Scanner\pca10056\s140\armgcc  

make  

cd C:\Users\%username%\Documents\nRF5\nRF5SDK15209412b96\examples\ble_central\NRF52840-Beacon_Scanner\pca10056\s140\armgcc\_build 

copy nrf52840_xxaa.hex C:\Users\%username%\temp  

copy C:\Users\%username%\Documents\nRF5\nRF5SDK15209412b96\components\softdevice\s140\hex\s140_nrf52_6.1.0_softdevice.hex C:\Users\%username%\temp  

cd C:\Program Files (x86)\Nordic Semiconductor\nrf5x\bin\  

mergehex -m c:\Users\%username%\temp\s140_nrf52_6.1.0_softdevice.hex c:\Users\%username%\temp\nrf52840_xxaa.hex -o c:\Users\%username%\temp\out.hex 

cd C:\Users\%username%\temp  

arm-none-eabi-gdb  

(gdb) target extended-remote com4

Note: here com4 is the COM-port number of "Black Magic GDB Server" that was noted above. If the number of COM-port is more than 10, then \\.\COM1x is used instead of COMx.

(gdb) monitor swdp_scan

(gdb) attach 1 

(gdb) file out.hex 

(gdb) y 

gdb) load C:/Users/%username%/temp/out.hex 

(gdb) quit 

(gdb) y

From this point, the Bluetooth Nordic nRF52840 module was ready for switching on/off water manipulators, on the base of the iBeacon water leak detector's data. The Black Magic Probe programmer was disconnected to Bluetooth Nordic nRF52840 module and to the PC.

Then the Bluetooth Nordic nRF52840 module was soldered to a DC-DC converter and a relay with this simple scheme:

Mobirise

The scheme is not complicated. Components are common, but specific requirements are noted below to ensure maximum service life.

Pos.ItemSpecific requirements
K1RY611012 (TE)12V DC driven, 1 or more NO, branded
R11K1/4W
R210K1/4W
U212V to 3.3VAn 12 to 3.3 DC-DC adapter, branded

The absolute good idea is to use a DC UPS (12V here) as for the nRF52840 module power as for the water manipulators power.

That all. Once a raindrop sensor detects a water leak, the iBeacon will start work on the air, and the nRF52840 being catch this signal, will close relay for switching water manipulators.

A software you can load from this site is free for a non-commercial use except for components for which their owners declared their own rights. Can be limited by local laws. No of your data will be collected with a software you can load from this site.

Subscribe for updates.

Created with Mobirise site templates