1. System Overview

The All-in-One Capacitive Soil Moisture Sensor is a sensor that aims to provide a reliable, low-cost, and easy-to-use solution for measuring soil moisture and temperature in plant pots. The sensor consists of a capacitive sensing PCB that is inserted into the soil and a Heltec CubeCell module that is located at the top of the PCB. So the sensor sits halfway in the ground with the electronics being above the soil inside a protective housing. The CubeCell module enables low-power LoRaWAN connectivity, allowing the sensor to send its data to the user-defined LoRaWAN IoT network. The sensor is powered by a 17330 Li-SOCl2 battery that can last for several months without replacement. The sensor also features a temperature sensor "in" the bottom of the PCB, which measures the actual soil temperature and helps to calibrate the moisture readings for different soil types. The sensor is designed to be durable and resilient in various environmental conditions, thanks to a protective epoxy coating that covers both the PCB and the housing. To install and use the sensor, one simply needs to insert it into the soil, water it well, and wait for a few days for the sensor to settle and give accurate readings.

2. Sensor Working Principle

Capacitive soil moisture sensors work by measuring the dielectric constant of the soil, which is a measure of the soil’s ability to store electrical charge. When the soil is moist, it has a higher dielectric constant than when it is dry, due to the presence of water molecules. The sensor consists of two electrodes that are inserted into the soil and an oscillator circuit that generates a high-frequency signal between the electrodes. The capacitance of the soil between the electrodes affects the frequency of the oscillator, which can be measured and converted into a digital value. If you want to learn more about how capacitive soil moisture sensors work, you can read this article by rbaron: How Capacitive Soil Moisture Sensors Work by rbaron.

The bottom part of my PCB is based on the Grove Capacitive Moisture Sensor by Seeed Studio. The electronics are a mix of the rbaron project "b-parasite" and my own creation. The basic working principle is the same as in the rbaron project. The needed square wave for the sensor is generated by the MCU (CubeCell) itself with a frequency of around 53 MHz.

I do not convert the capacitance value to a moisture percentage. According to the professional horticulture advisor Norbert Gröger, the conversion is not accurate for these kinds of sensors. To get a specific output, I first need a good sample of sensors and pots with the same soil inside and then calibrate the readings for that specific soil type. However, setting minimums and maximums is more effective and closer to real life. As also a soil temperature sensor is embedded into the PCB temperature could also been taken into consideration during the calibration. More on that under "11. Temperature Calibration".

3. Hardware Components

The main hardware components of my sensor are:

I chose these components based on their reliability, compatibility, and power efficiency. I already knew the CubeCell module and had experience developing with it (It has some weird quirks). It is also Arduino compatible, which is suitable for simple sensors like this. The DS18B20 is a well-known temperature sensor I have used in other projects. Other components were chosen because they worked well in previous projects or were inspired by rbaron’s project. The antenna matching was done by myself.

I designed the PCB using Autodesk Eagle/Fusion 360 and hand-assembled and soldered it. The housing was designed in Fusion 360 and later printed in PETG on my Anycubic Mega X. For antenna testing and calibration, I made a variant of the housing that was split with a hole for an optional SMA connector at the side of the board.

The dimensions of the sensor including the housing are roughly 140mm x 32mm.

The cost of building one sensor is flexible and depends on the price of the individual parts. I estimate that the cost per sensor can be around 30€ to 40€ if you build multiple sensors. Keep in mind that the more you build, the better the cost-effectiveness. The epoxy is rather expensive for just one of these sensors, but if you build a couple, it is definitely worth it.

4. Sensor Circuit Development

I designed the sensor circuit by reading many articles about the topic and taking inspiration from rbaron’s project. Before getting to the real parts, I made some online simulations on falstad.com (Link to the actual simulation developed). After some trials, I got to the version which can also be found in my GitHub Repo. It has an interactive slider to simulate the capacitance value for the sensor PCB, which basically determines the output voltage range of the whole sensor. As per design, the Heltec CubeCell Module has only one analog input to measure voltage which is able to measure from 0V to 2.4V. Therefore, I optimized the circuit to output to that specific range. To validate my findings, I built the circuit up on a breadboard with some different resistors. For that, I also ordered some of the sensor PCBs with just the bottom part which I could hook up to the circuit just for development. With a 4-channel oscilloscope, I monitored multiple values at once (for example, square wave generated by Arduino Nano and the output voltage), with which help I could determine that the best resistor value is 127kOhm. As a frequency, I used both on the Arduino Nano, as well as on the Heltec Module a square wave frequency of roughly 53kHz.

After making that finding, I converted the schematic into a PCB design and also added a button and LED which were not used at the time of writing this article. I intended them for use during calibration for example.

To measure the actual soil temperature with my sensor I wanted to embed a temperature sensor inside the soil. There were multiple options to do so but in the end, I decided on using a normal temperature sensor which I could just read out with my MCU and already have a ready-to-use temperature value. As I have previously worked with DS18B20 in some of its other formats I decided on using its IC from the DS18B20Z in this project. Would I do a second revision of this project, I would probably use another IC temperature sensor, as the DS18B20 is rather outdated and also very expensive. Probably there are better selections out there. By selecting this sensor I faced the issue that by just sticking it onto the bottom of my PCB the sensor would create a rather huge bump which would be prone to be knocked off and also when inserted into the soil, the sensor might create a small cavity which can reduce the contact between the soil and the capacitive soil moisture sensing part, which would lead to bad readings. To circumvent this issue I tried mounting the sensor inside the PCB itself. Therefore I designed my own footprint for this sensor and milled it out on PCB-Mill until the dimensions were right for me. 

The special idea is that the "feet" of the sensor have a little hook/flat part on the end. This part should rest upside-down on the pads while the actual sensor part is resting inside a cut-out in the PCB. By mounting it that way the sensor sits almost flat "inside" the PCB and the only thing sticking out are the 0.1mm thick feet. Now the only challenge left is protecting the sensor. I will get into more detail about this in "7. Epoxy Coating and Environmental Protection".

5. LoRaWAN Connectivity

The LoRaWAN connectivity was easily implemented with the help of the CubeCell module. For another project, I wrote myself a small encoding and decoding protocol which I named Minerva. It helps me to quickly adapt the code for a new sensor but also keeps some fundamental functionality in place. It is kind of my standard template for sensor development right now. For example, I have a functionality already built in to change the duty cycle in which the sensor measures and sends data via a simple LoRaWAN downlink.

As I use TTN (TheThingsNetwork) for all of my LoRaWAN projects the payload decoder which can be found in the GitHub Repo is developed and tested specifically with that in mind. Probably it can be easily adapted to other platforms as well.

6. Antenna Testing

In previous projects, I was building my own helix-antennas, which worked great but are really a pain to do sometimes, especially on scale. So this time I decided to try out a PCB antenna that has been designed by Texas Instruments (more particularly Richard Wallace). All the documentation and testing of that particular antenna can be found here: Design Note DN038 - Miniature Helical PCB Antenna for 868 MHz or 915/920 MHz By Richard Wallace Without any components mounted to the PCB I soldered on an SMA connector on the site of it, which is only needed during development to finally tune the antenna. 

This is needed to get the best efficiency out of it and so maximize the range by using as most of the transmitting power as possible. As I live in Europe, my goal was to tune the antenna to 868 MHz. While testing with a Vector Network Analyzer (VNA) I also had a modified housing around the sensor which had a hole just for the SMA connector. All design files of the project can be found in the GitHub Repo. The first results were very promising. Even without any matching, I was able to get an attenuation of -11 dB which is already really good. Tho the antenna was rather broad band and not very precise on this one specific frequency. The Smith chart showed that the antenna was slightly mistuned. With the measured values put into SimSmith I was able to figure out which components were needed to get a very good antenna-matching circuit: one coil around 550pH in series and one capacitor around 2.3pF in parallel. I picked the closest values I could find and soldered them onto the already existing pads on the PCB. I then hooked up the PCB again to the VNA and was baffled by the values I could see. The antenna is now pretty well tuned for the EU LoRa bands and on 868 Mhz I was able to get an attenuation of almost -27dB which really really good. For such a small antenna it should perform well in real-life scenarios.

More pictures regarding this topic and other parts of the project can be found in the GitHub Repo.

7. Epoxy Coating and Environmental Protection

While I was doing my research, I found multiple articles on the internet that stated that yes capacitive soil moisture sensors have a longer lifespan than cheap resistive soil moisture sensors BUT that still after some time water creeps in under the solder mask and corrates the Copper of the PCB. Also, I wanted to protect the sensor PCB as much as possible from the environment to reduce the risk of scratching the solder mask by hitting on small stones in the soil for example which would also let water touch the copper layer.

But the most important reason for a needed epoxy layer is the temperature sensor which sits at the bottom of the PCB to measure the actual temperature of the soil.

As I was doing my research I found that not all epoxy resins hold up in the wild as well as others. After considering a couple of different resins I could not make a final decision based on real facts but rather on what seemed best to me. In the end, it was clear to me, that this was a kind of trial-and-error process. So I settled on the "Eco System" by (to me) local company Epodex. As the name implies this one is really good for coating and sealing things and is also used in building boats. In my thoughts, this seemed pretty good to me as salt water can be very aggressive to certain materials, and so hopefully this coating would also survive its life in the soil.

8. Housing and Rotary Device for Epoxy Distribution

Because the epoxy needs some time to cure, I knew I would need some kind of rotary device that would rotate the epoxy-covered pieces to ensure even coverage all over. I decided to make this a two-step process.

The first part is attaching the outer threaded part to the PCB. For that, I designed a little jig in which the PCB can stand. 

The small 3D-printed part should then rest roughly between the two lines on the PCB. To ensure that the epoxy and plastic part stick permanently to the PCB, the PCB has two holes through which the epoxy can flow, when filling up the small plastic part with epoxy resin. To seal the plastic part as best as possible where it has a hole for the PCB, I used some "sticking gum" which is normally used to stick pictures or other things to the wall. This method worked okay but I could not get a perfect seal, unfortunately, so it was a pain to remove it later after the epoxy had dried. In the end, it still worked well enough to continue working on the sensor. Probably it would be better to first seal the gaps with the gum and then pour a bit of UV resin around it from the top and cure it instantly and only then pour in the rest of the epoxy. After a day of curing, I proceeded with the next part.

The second part can be done on the rotary device. For this, I used a 12V DC motor with an RPM of 6 that I had lying around. It is not perfect but it worked very well for the first run of sensors I did. It is important to have enough weight in the back otherwise it will tip over.

But then one can just screw on the PCB with the smaller plastic part already attached and the top part of the housing onto the other gear. In theory, this system should be easily modifyable to handle more sensors at once. Even tho I printed the housing out of PETG, I wanted to make sure the housing was as waterproof as possible. That is why I decided to coat the top part of the housing as well. The biggest issue with the gear system was that over time because of the rotation, one of the epoxy-coated parts got loose as it unscrewed itself. So in a new version, another gear should be added so that both parts turn in the same direction. Nevertheless once screwed on, the epoxy can be mixed according to the instructions and applied with a brush. I made sure to not touch one of the gears with the brush as I feared to epoxy both parts together. Once everything was nicely covered I let it rotate on the device for around 2 to 3 days to make sure the epoxy was nicely cured. It is recommended to let cure for another 3 to 4 days to let the epoxy harden completely.

9. General Testing and Findings

In total, I had one sensor run for a period of 5 months with some time not being monitored as my home server was not running at this time. The sensor worked flawlessly in that time sending the data regularly. It was able to withstand the water and the soil. Even while watering the plants when approximately the bottom part of the top sensor housing was 2cm underwater, no water was protruding into the housing. The sensor was able to easily detect watering events and it showed when the soil was getting dryer.

So far so good, but it is not all roses, I´m being honest here. It is not clear to me yet if some part of the data acquired during the drying phase could also be related to temperature changes. Over a longer period, it almost seems like a drifting phenomenon can be seen. But to actually prove this I would need to run this sensor in a more controlled environment besides a known good sensor. Hopefully, I will be able to do so in 2024 with the help of Norbert Gröger at one of his client's places. Another thing that I noticed is that after some time it seemed like some reaction was going on under the epoxy on top of the PCB. 

After talking to some people it might be that I have not cleaned the PCB properly before applying the epoxy resin. But this is not that big of a deal as it seems to not affect the water tightness just the looks of the sensor. Furthermore, the whole applying process of the epoxy can be further improved tho it served its purpose very well. What I did not mention before but besides the epoxy jig, I also designed a programming jig for this PCB. It worked okay as well but once developed to a final form a new programming jig should be developed.

10. Battery Life

The battery life of this device is very promising. All data was measured with a Nordic Power Profiler 2. In deep sleep, the sensor only consumes a mere 3uA. During one sending cycle which takes 6.5 seconds on LoRaWAN data rate SF8BW125, the sensor consumes on average 3.2mA with peaks during transmission of above 100mA. 

Putting this into an IoT Battery Calculator we get a battery life of roughly 10 years, which is more than I was aiming for at a duty cycle of 20 minutes.

This is even taking into account 15% unusable battery capacity due to low voltage even tho I think it should roughly be in the neighborhood of 5%. In reality, the lifetime should be a bit shorter as the version tested had a wrong installed DS18B20 which reduced the used energy. Still, a lifetime of more than 3 years can be expected at this data rate.

11. Temperature Calibration

This part still needs to be done. After comparing the sensor to a known good sensor I want to figure out if some temperature calibration is needed. To be able to do a temperature calibration it would be best to have a small climate chamber and then go through a calibration schema like described by Joshua Hrisko on makerportal.com, but with the added variable of temperature.

12. Conclusion

In conclusion, I am very happy with the first results I got and I want to continue a bit on this project in 2024, at least do a test in a real-world environment besides other industrial sensors.

As for most of my projects, I follow them out of pure curiosity and with the idea of learning something new. With this project, I could follow many of my interests as I could do research, hardware development, embedded development, CAD design, and in the end also some configuration of my NIG (Node-Red, InfluxDB, Grafana).

So for me, this project was so far a success but there is still a lot to be done to get into a finished state.