Maker Pro

Battery-powered IoT Moisture Sensor With Wi-Fi

June 21, 2020 by Sylwester Bala

Build a WiFi 2xAAA battery powered moisture/water sensor in minutes and monitor on a smartphone. All this with ZERO code

In this project, we present how to build a moisture/water sensor with a battery level monitor in less than 30 minutes. The device monitors a moisture level and sends data to a smartphone over the internet (MQTT) with a chosen time interval. 

Use any MQTT mobile app to receive and visualize the data. The device is powered on a 2xAAA batteries (or a single AAA) if configured properly can last for years. It connects to the internet over a Wi-Fi network by using Things On Edge Cricket Wi-Fi module, so you do not need an extra IoT HUB.

Before you start, please make sure you have the following components:

If you are ready let's get started!


You need to connect batteries and the moisture sensor to the Cricket module with the following steps:

  • Connect battery VCC / + (red cable) to Cricket's BATT port (NOTE: The Cricket module can be powered either on AA or AAA batteries)
  • Connect the sensor VCC / + (green cable) to Cricket's 3V3 port (NOTE: 3.3V port supplies stable 3.3V regardless of a battery voltage level)
  • Connect the sensor AOUT analog signal (yellow cable) to Cricket's IO2 port (NOTE: This port can be configured as an analogue signal. The data will be reported to your smartphone)
  • Connect the sensor GND / (-) (blue cable) to Cricket's GND port
  • Connect the battery GND / (-) (black cable) to the same Cricket GND port

Well done you have successfully assembled the device!

Before you start using the device it needs to be configured in Developer Portal. Please go to the next section.

Configure Your Device in Developer Portal

You configure the device entirely OTA (Over The Air) on Things On Edge - Developer Portal ( The configuration is retrieved by Cricket via the internet when connected to your Wi-Fi (see the next section). Now let's configure it first.

For the moisture sensor it is recommended to set the following configuration:

  • Set IO2 as an analog input
  • Report moisture level every 2 hours - it will make your device running on 2xAAA alkaline batteries for more than 2 years.

Open TOE Developer Portal from any browser either from PC or mobile. You must register/login to Developer Portal to activate and configure the device in your account. Otherwise, the device won't work.


After successful login / registration you need to click "Add new" device to activate your device in the system. You need to use the unique serial number printed on a label stick on the back of Cricket.


WARNING: You must keep the serial number for yourself only. Do not share it with anyone else. The serial number is a private MQTT communication account between your device and a smartphone or any other internet service. In other words keep it as secret as a PIN to a credit card.

Now you can configure your device.


Set the following configuration:

  • RTC: ON
  • RTC Units: Seconds (to be changed later)
  • RTC Units Value: 30 (to be changed later)
  • IO2: Analog In
  • IO3: Off
  • Battery monitor: On
  • Battery divider: 0
  • Temperature sensor: Off
  • Force updates on - IO1 Wake Up: On (to be changed later)
  • Force updates on - RTC Wake Up: On (to be changed later)
  • Post Events: leave all empty

Once you set your configuration hit the Save button.


Well done! You are almost there! Now you just need to connect your device to the internet over your Wi-Fi network. Please follow the next section how to do it.

Connect to Wi-Fi Network (internet)

In a few steps you will connect your device to the internet over your Wi-Fi network. All you need to do is to activate Cricket's private Wi-Fi hotspot and then open a private web page to pass your Wi-Fi network credentials. Please follow the steps below:

  • Press and hold a button on the module for 5 seconds until the LED is constantly lit.
  • Once the LED is constantly lit Cricket opened a private Wi-Fi hot spot. Connect from either a laptop or smartphone to the hot spot with the following credentials: SSID: toe_device  No password is required

NOTICE:make sure LED is still ON! If is OFF repeat the steps from the beginning


Now you can pass your Wi-Fi network credentials and click CONNECT. If you passed correct SSID and Password then after few seconds the device should report it is online and the LED will be OFF.

Congratulations! Now your device is live and connected to the internet! You can start reading the data from the sensor on your smartphone or any other internet services. Please see the next section as an example.

Using MQTT client on mobile

You can use any preferred MQTT client. However for the completeness for this project let's use IoT MQTT Panel application to receive and visualise data. The Cricket module connects through low-latency Things On Edge MQTT broker ( You just need to do the following steps:

  1. Configure a server connection with the following details:
    Server / Broker IP address:
    Port number: 1883
    Network protocol: TCP

  2. Add device e.g. "Moisture Sensor"

  3. Goto advanced options:
    Username: your_cricket_serial_number
    Password: your_cricket_serial_number
    Connect automatically: YES

  4. Press the Create button

  5. Press ADD PANEL

  6. Select: Line Graph

  7. Set the details for graph 1 to read data from sensor (from the Cricket IO2 port)
    Panel name: e.g. Moisture sensor
    Topic for graph 1: /your_cricket_serial_number/io2
    Show area: YES
    Show points: YES

For more information please refer to the attached screenshots from IoT MQTT Panel below.



Your moisture sensor is already working and sending data over the internet to your smartphone.

The battery level can be monitored via MQTT using dedicated topic:


Optimise your device to run for years on batteries

You can make your device to run for years on these batteries. You just need to make the following changes:

  1. wake up every couple of hours e.g. 2 hours
  2. send data to the internet only when the sensor's value changes

Open the TOE Developer Portal ( and set the following configuration:

  • RTC: ON
  • RTC Units: Hours (send data only when changed)
  • RTC Units Value: 2
  • IO2: Analog In
  • IO2 Analog Divider: 3
  • IO3: Off
  • Battery monitor: On
  • Battery divider: 3
  • Temperature sensor: Off
  • Force updates on - IO1 Wake Up: Off (send data only when changed)
  • Force updates on - RTC Wake Up: Off (send data only when changed)
  • Post Events: leave all empty

Monitor a battery level

In principle the less module communicates to the cloud, the better power saving. Cricket requires energy for both sending an update to the cloud and evaluating values of attached sensors only. It is true 0A when is OFF.

In practice it can send 10k messages to the cloud using 2xAAA alkaline batteries and more than 15k when used lithium batteries.

In this case the battery monitor configuration is also set to update cloud service when the battery level value changes only. Additionally battery consumption can be reduced by lowering resolution of measuring an analog signal.

The battery value can be calculated as follow:

Vbatt = val * (3.5/256) * 2^Battery divider

where val is reported battery level from MQTT service.

In this case 1.4V indicates low level of the alkaline battery and suggests replacing it, the value reported via MQTT is 13

Vbatt (V) = 13*3.5/256 * 8 = 1.42V

Minimum value for the Cricket is 1.1V.

IO2 analog input configuration

  • IO2: Analog In
  • IO2 Analog Divider: 3

These values reduce resolution of the analog signal and significantly reduce battery consumption, module will reduce time sending new updated values to the Cloud.

Likewise, the analog value can be calculated using the following formula:

IO2 (V) = io2_val*3.5/256 * 2^IO2 Analog Divider

Analog divider of 3 provides resolution approx. 0.1V

Receive even more data ...

There is much more you can play with your current device such as reading built-in temperature sensor, read the battery level, and more. Please checkout more information on Things On Edge (


Thank you for taking your time! If you enjoyed building this moisture sensor I would really appreciate if you could spread the word among your peers. If you have any feedback or suggestions how to improve it and make easier for other folks, I would be more than happy to do it. I'm opened for your suggestions.

Many thanks & Enjoy!


Sylwester Bala

Technologist and entrepreneur who loves solving problems!

Related Content


You May Also Like