This project demonstrates how you can build moisture sensor with battery level monitor in less than 30 minutes. The device will be monitoring a moisture level and sending data to your phone over the internet (MQTT) with a chosen time interval. We will pick up one of MQTT mobile apps to receive and visualise the data. The device will be powered on a 2xAAA batteries (it can also be on a single AAA), if configured properly can last for years. It connects to the internet over Wi-Fi network by using IOT Cricket Wi-Fi module.
Before you start, please make sure you have the following components:
- Cricket Wi-Fi module (https://www.thingsonedge.com/)
- Soil Moisture Sensor
- 6 way terminal block (optional)
- 2xAAA batteries (either AAA or AA)
- AAA batteries pack (either AAA or AA)
- 3x jumper wires
If you are ready let's get started!
AssemblySolder the 6-way terminal block to the Cricket module. The terminal block makes it easier to play around with cables.
Now 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 portNOTE: The Cricket module can be powered either onAA or AAA batteries
- Connect the sensor VCC / + (green cable) to Cricket's 3V3 portNOTE: 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 portNOTE: This port can be configured as an analogue signal. The data will be reported to yoursmartphone
- Connect the sensor GND / - (blue cable) to Cricket's GND port
- Connect the battery GND / - (black cable) to the same Cricket GND port
Before you start using the device it needs to be connected to WiFi and configured.
Connect to Wi-FiAll you need to do is to activate Cricket's private Wi-Fi hotspot (toe_device) 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
- Cricket opens a private toe_device Wi-Fi hotspot. Connect from either a laptop or smartphone to this hotspot. No password is required
- Once connected, a private web page should be opened automatically. If not, open it manually from a browser: http://192.168.4.1/index.html
- Now you can pass your Wi-Fi credentials and click CONNECT
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.
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
More information on how to configure Cricket can be found in the documentation here.
Let's now go and configure your phone to receive data from Cricket.
Receive data on you phone using MQTT clientYou 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. We configure Cricket to use TOE_MQTT broker but you can use any other MQTT broker. So in the app you just need to do the following steps when using TOE_MQTT:
- Configure a server connection with the following details:
Server / Broker IP address: mqtt.thingsonedge.com
Port number: 1883
Network protocol: TCP - Add device e.g. "Moisture Sensor"
- Goto advanced options:
Username: your_cricket_serial_number
Password: your_cricket_serial_number
Connect automatically: YES - Press the Create button
- Press ADD PANEL
- Select: Line Graph
- 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
Please see the screenshots from IoT MQTT Panel below how you can configure the app to receive and visualise the data.
Congratulations!
Your moisture sensor is already working and sending data over the internet to your phone.
The battery level can be monitored via MQTT using dedicated topic /your_cricket_serial_number/batt
Optimise the battery usage of your deviceYou can optimise your device to run for years on batteries. You just need to change the following:
- send data to the internet only when the sensor's value changes
- wake up every couple of hours e.g. 2 hours
Set the following Cricket's 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
In principle the less module communicates, the better power saving. Cricket requires energy for both sending and evaluating values of attached sensors.
In practice it can send 10k messages using 2xAAA alkaline batteries and more than 15k when used lithium batteries.
In this case the battery monitor configuration is also set to send update only when the battery level changes. Additionally battery consumption can be reduced by lowering resolution of measuring an analog signal.
The battery voltage can be calculated as follow:
Vbatt = val * (3.5/255) * 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/255 * 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.
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 and visualise even more dataThere is a lot more you can play with your current device such as reading built-in temperature sensor add extra peripherals etc.
Please checkout more detailed information in the documentation: https://www.thingsonedge.com/documentation
FeedbackThank you for taking your time! If you enjoyed building this moisture sensor I would really appreciate if you could spread the word. If you have any feedback or suggestions how to improve, we are happy to hear them.
Many thanks & Enjoy!
Comments