ESP32 Soil Monitors Tap Into Ultra-Low Power Mode

Soil moisture sensors are cheap and easy to interface with, to the point that combining one with an Arduino and blinking an LED when your potted plant is feeling a bit parched is a common beginners project. But what about on the long term? Outside of a simple proof of concept, what would it take to actually read the data from these sensors over the course of weeks or months?

That’s precisely the question [derflob] recently had to answer. The goal was to build a device that could poll multiple soil sensors and push the data wirelessly into Home Assistant. But since it would be outside on the balcony, it needed to run exclusively on battery power. Luckily his chosen platform, the ESP32, has some phenomenal power saving features. You just need to know how to use them.

The custom board can read from six soil sensors.

In his extremely detailed blog post, [derflob] goes over some of the tricks he used to eek out as much runtime as possible. The big one, and arguably the key to the whole project, is his use of the ESP32’s Ultra-Low Power coprocessor (ULP). This powerful feature allows the microcontroller to do some useful work, albeit with a reduced instruction set, without waking up the power-hungry primary processor.

Since the ULP can read from the ADC, he was able to craft some assembly code that only wakes the CPU if the readings from one of the six connected sensors has changed more than a set threshold value since the last update. This keeps the chip asleep the majority of the time, and so far, [derflob] says his board has been humming along for six months on a single LiFePO4 18650 cell. If you’re not so keen on diving into assembly, we’ve seen a similar technique accomplished with a simple circuit that only wakes the microcontroller when there’s work to be done.

So where does the project go from here? Now that the PCB is largely finalized, [derflob] is turning his attention to waterproofing both it and the sensors so they can survive outside in the elements. Some kind of epoxy encapsulation is probably in order, though that will be a project for another day.

26 thoughts on “ESP32 Soil Monitors Tap Into Ultra-Low Power Mode

  1. I wonder how often the sensor is sleeping and waking up. I’m no firmware engineer by a long shot, but by using the WiFiManager Arduino library by tzapu, I made an ESP8266 sensor that runs a time of flight measurement and wakes up every 24 hours, takes a measurement, sends it to a server and goes back to sleep. It hit a year of battery life on two AAs exactly today. Extrapolating the battery curve indicates that it should make at least two years. A test with hourly updates ran 250 days.

    1. Probably a dozen or so times per day, depending on what the threshold limit is, and how big the flower pot is (drying rate).

      When optimizing for low power consumption, the more important point is to make sure you shut everything down. Especially if you’re using Arduino, the libraries tend to switch things on at init and there’s little or no documentation (except the libraries themselves) to say what is on and what is off – which can take some serious effort to discover.

      For example, on the Arduino MKR boards, the default is to switch all the input buffers on but leave the pins in a floating (Hi-Z) state, which means the inputs are picking up static noise and the input amplifiers keep consuming up to a milliamp of current no matter what sleep state you set. A bubblegum patch on this is to set all the inputs to pull up in your code.

    2. It very much depends on how much is “happening” and how many sensor are connected in parallel. For the single sensor you can see in the picture, it normally wake maybe 10 to 15 times a day. However after watering will wake much more often for a couple of hours until the water has spread through out the soil.

      One of the sensors on my balcony with three sensors in parallel wakes about 40 times a day at the moment, with a similar increase after watering.

  2. Ive seen a fair few reports on the interwebs RE: these soil moisture sensors corroding and becoming almost useless after a while. Does anyone have any recommendations for a decent soil moisture sensor that is reliable over a greater span of time?

    1. There are two types of probes, resistive and capacitive. The resistive ones are prone to electrolyzing when fed DC as the moisture in soil makes for a good electrolyte, but this can be alleviated by switching measurement direction every other measurement or using AC. The capacitive ones generally fare a lot better as their metal plates are not in contact with the soil.

    2. Look up some TDR soil moisture sensors. They’re more expensive and use more power, but they’re more accurate and less variable in different soils.

      Any sensor with bare metal rods directly inserted are going to corrode. Even aluminum probes will do so over time in acidic soil with fertilizers and other stuff thrown in the mix. In the worst cases I’ve seen, the runoff from the field has a PH similar to orange juice, and things like aluminum sluice gates in the irrigation trenches will simply disappear.

      These capacitive sensors are probably going to last the longest because they don’t use a direct galvanic connection with the soil, but these Chinese sensors aren’t coated in any special material to prevent water absorption into the circuit board itself, so over time it picks up water and de-laminates or corrodes the traces off of the board.

      1. I looked them up, can’t seem to find the sensor itself for sale anywhere. I found a meter for over £1000 and an rs485 probe for £100.

        Are they that expensive or just not available for public purchase?

        1. They’re in the “we’re targeting farmers and research institutes” category, i.e. volume customers, so you have to ask for a quote and they’ll make up some price depending on how much they like your face.

          It’s not possible to buy the “sensor” alone because it has some high speed precision electronics. You need to buy the probe and adapt that to your circuit – there are ones with voltage output, frequency output, RS output… etc.

          1. Or rather, the sensor is just two or three metal rods in the ground, and all the intelligent stuff happens in the interface electronics that translates the signal to something you can actually use.

            You can perform TDR on an oscilloscope and a signal generator yourself, just stick the wires into the ground. The delay between the input and the reflected wave is proportional to the dielectric constant of the surrounding material. The difficulty comes in interpreting the results and making it work consistently.

    3. Yes! Avoid the resistive sensors and go for the capasative ones. Sometimes you can see the pcb from the sides on some of the cheaper sensors, but you can easily make it watertight with some nailpolish.

    1. I am using standard ESP32-WROOM board without any voltage regulator, exactly due to the reason you mentioned. Instead I am directly feeding the ESP32 with a LiFePO4 battery, which have a voltage profile, that fits the ESP32’s

      The draw back is that they are more expansive and have lower power density than Li-Ion batteries.

  3. From a Corrosion Engineer: Copper ground rods last a very long time in normal soils unless there are lots of amps passing from one to the other. You could make them of #10 AWG copper wire. Make sure your home made electrodes are exactly the same material and with no solder joints exposed to the soil. In very acidic soils you could use monel (alloy of copper and nickel). Here I assume that your measuring circuit is a resistance measuring (Wheatstone bridge) type. Soil conductivity (the inverse of soil resistance) is easy to measure and is non-linearly proportional to moisture. The absolute value measured can vary from place to place depending on changes in soil composition and temperature, fertilizers in use, salt deposited from sea breezes if near the ocean, and so on.

  4. Instead of epoxy, place circuit in a small project box with an o-ring seal and include a desicant pack to absorb any trapped moisture to prevent condensation. I have low power mailbox open sensor with a Z-wave transmitter running for over a year on one small lithium battery that still reads 100%. I expect it to run for five years…at least

    The sensor triggers my Alexa devices to announce “You have mail”. Your device could ask you to water your plants.

    1. A box would solve the issue of waterproofing the device, yes, I was thinking about that too.

      However, the sensors stuck into the soil have some unprotected circuit as well, which messes with the measurement, if it gets wet. Additionally, I have seen the solder mask peeling off on some sensors, laying the raw copper bare.

      1. I actually use these to track moisture level in my lawn. https://spruceirrigation.com/sensors. They don’t need to be used with Spruce irrigation controller. These are Gen 3. They are greatly improved over older generations
        I don’t know how accurate the measurement is but it doesn’t really matter. I was able to correlate readings with how the grass looked. When reading 25 the grass needs watering. After 3/4″ of water (measured using a deep 12″ square baking dish, the reading was 45. Using these I cut down on over watering saving more than the sensor cost in one season of use. So far they have been rock solid on connectivity with my SmartThings hub and after 7 months battery is is still 100%. I was going to build my own sensor but determined quickly doing that would cost more in time, materials and R&D the devices cost.

  5. Using nickel rods as electrodes avoids corrosion in most environments. Nickel welding rods work. Also, don’t power the electrodes unless a measurement is taking place to reduce galvanic corrosion.

Leave a Reply to SayWhat?Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.