An ESP32-based soil moisture sensor.

Similar projects worth following
w-parasite is a WiFi-enabled, battery-powered soil moisture sensor, built around an ESP32.

It works by reading the soil moisture level and transmitting that information via MQTT messages.

How It Works

Parasitic Capacitance

To measure the soil moisture, the board has a parasitic capacitor (really just a pair of PCB traces) that changes its capacitance according to how wet the soil around it is. The ESP32 feeds a square wave to this capacitor through a resistor and we estimate its capacitance by looking at the charge/discharge curve of this tiny circuit. I wrote more details about this cool trick here.

MQTT messages

DiagramWhile the ESP32 + WiFi are on the energy-hungrier side of battery powered SoCs, on the positive side, we can directly pipe our sensor readings to an MQTT broker. Every so often w-parasite wakes up from its beauty sleep, quickly takes a reading, connects to WiFi, write to a few MQTT topics and goes back to bed.

Powering the Sensor

The board can be powered with rechargeable LiPo/Li-Ion cells. I have experimented with two main types of battery:

  • LIR2450 Li-Ion coin cells. They are super compact (as in the photo above). With around 120mAh, they can only source short peaks of 200mA, which is below what the ESP32 expects. Using them poses a challenge on capacity and current, and that's where the fun is;
  • LiPo/Li-Ion cells. They are generally a lot bigger but usually pack up to 3000mAh. They take a lot of space but comfortably powers w-parasite for well over a year;

Battery Life

WiFi and ESP32 are not usually a good choice for ultra low power devices, but since we can get away with long periods of deep sleep, we might just barely get away with it. When active, the ESP32 can consume peaks of over 200mA, and it goes down to around 15uA in deep sleep. The name of the game is trying to keep the active time short - cutting it down from 2 seconds to 1 second essentially doubles our battery life. As of writing, I managed to bring the runtime down to around 400-500ms, but there is still room for improvements.

I put together this spreadsheet as a quick way to estimate battery life. Here are some example scenarios:

  • LIR2450 cell (120mAh), transmitting every 30 minutes: around 80-90 days.
  • 1200mAh LiPo, transmitting every 10 minutes: over a year;
  • 18650 Li-Ion (e.g.: 2700mAh), transmitting every 5 minutes: over a year


Schematic PDF.

Adobe Portable Document Format - 41.26 kB - 03/04/2021 at 17:21


View project log

Enjoy this project?



T Smith wrote 04/01/2021 at 10:13 point

@Raphael Any update on when these will be available on tindie?

  Are you sure? yes | no

T Smith wrote 03/22/2021 at 10:07 point

This looks great for my Loxone smart home. Where did you get the boards made?

  Are you sure? yes | no

T Smith wrote 03/22/2021 at 10:18 point

Ahh, I see some people have asked about purchasing these already. I would be after x2 initially for inside. 

Then a little PETG case I could make to protect outside ones.

  Are you sure? yes | no

T Smith wrote 03/22/2021 at 11:20 point

@Raphael Actually I see you have most of the files on github. Did you just hand solder the components or get jlc to do the most populated side?

  Are you sure? yes | no

Raphael wrote 04/01/2021 at 13:07 point

Hey there. Answering your questions:

1. I actually hand soldered these myself. They are mostly 0805 components, which are still okay to solder by hand.

2. About the tindie shop - I'm actually working on the new version of this sensor, which I just open sourced today on I will be focusing on that from now on. These I'm getting pre-assembled by JLCPCB.


  Are you sure? yes | no

T Smith wrote 04/01/2021 at 13:16 point

Hey. Thanks for getting back to me. I'll hang on for you and wait on your feedback :)

  Are you sure? yes | no

William Turner wrote 03/17/2021 at 05:27 point

Have you considered using the soil itself as a power source? Several years ago I gave my wife a hygrometer that has two probes and an analog needle gauge. The meter is able to move the needle using the soil and the dissimilar metals of the two probes. Yes, the analog meter is most likely operating in the uV range...but maybe you could charge up a “supercap” while you’re in sleep mode.  Another source of power to consider would indeed be “parasitic”...and that would have adjacent units leech power from the active transmitter(s)...much like RFID.

  Are you sure? yes | no

Raphael wrote 03/17/2021 at 12:57 point

That's an interesting thought. I wonder what's possible. I saw some people working with energy harvesting ICs and they seem super cool. I think it's mostly biased toward harvesting vibration/solar/thermal energy. 

  Are you sure? yes | no

William Turner wrote 03/17/2021 at 21:50 point

If your plants (with gauges) are located outside...I would imagine your options for available energy sources would increase versus being inside your home. I would consider a Peltier device utilized in a reverse configuration where heat OR cold is used to generate a current flow.  I’m curious if a transparent water reservoir could collect heat from the sun during the day...then act as a “thermal bank” after sunset to increase power generation time and/or output power.  The Peltier device(s) would be mounted on the bottom side of the reservoir. Two additional thoughts with this reservoir idea come to mind.  First, would using a more “exotic” material inside the reservoir be capable of maintaining its temperature for a longer period of time. Second, provide as much coverage of the reservoir’s underside as possible with Peltier device(s). As there are many sized devices on the market...“cost to power output ratios” would likely decide your usage scheme.  As in, usage of multiple smaller devices (array) versus a single larger device to ? Of course, abandoning the concept altogether is always a choice.  

SOUND has several options, for example, piezoelectric devices (circular copper-colored speakers that output a horrifically loud alarm sound with a voltage is applied...quite often used as pickups in acoustic guitars) generate a current when used in a reverse manner like a microphone. Placement of the device at the end of some type of “horn-like” structure could serve as a concentration mechanism (imagine a 1920’s era record player) increasing the dB l/SPL levels presented to the piezo device. You could use an air-vent (found on loud speakers/guitar amps, etc.) mounted on the side of one of your larger plant pots. Attach flexible tubing (maybe 2” diameter) to your vent...feed wiring down the length of the tubing...then bury it in a coiled fashion terminating at a project box containing your piezo sensor. This configuration would be similar to Bose’s “Wave” technology in its ability to direct, amplify, and frequency modify audible signals.  You would also have the advantage of hiding what I would consider a structure lacking visual appeal. Accommodations for keeping water away from your piezo would seem obvious...and I have no idea if output efficiency would be affected by the direction (top down or bottom up) you bury the tubing. Placing the piezo project box at the top of your plant pot would be the only obvious advantage as it permits easier access and less damage to your plant if you need to dig it out. Other sound devices such as electret microphones, super small speakers, salvaged microphone internals and other such materials will generate a current when exposed to some level of sound. There is an Arduino speaker module with a ~1/2” diameter speaker mounted on it. The speaker cone is a thin plastic film. I have one of these modules in my parts boxes...I’m curious what type of current it might be able to create when wired as a microphone. With all of these devices, it becomes necessary to know the dB/SPL levels necessary to generate a useful current. If they require anything over 85dB to be functional...they become useless devices. Personally, I would consider anything over a ~60dB useless. Dishwashers operating at ~40dB are examples of tech I love. cells would be the obvious device for this class. However, I suspect there are also other novel devices I’m not familiar with.  

WIND...I’m imaging pinwheels or other “windmill-like” devices and belt-driven generators (hobby motors) stuck in each pot to generate enough power to charge a “SuperCap” or possibly recharge a battery during sleep mode.  You would have a rather festive looking herb garden and might run the risk of eliciting questions as to what type of “herbs” you’re growing. 🤪 A single larger windmill would likely be a better idea as it could be used to power all of your gauges. Additionally, the use of “LED wire” (often seen shoved in glass jars & such for decoration) as camouflage and carrier for 30 AWG (or smaller) transformer wire could create your power distribution system. I’ve used these LEDs in hanging pots of dangling vine plants. I used a central star/hub configuration wrapping the LED wire around 10-12 of the vine lengths.  This created a really nice ambiance in the evenings as we sat on our patio. 

VIBRATION...I’m drawing a blank on this one right now.

One of my hobbies is music (play synths, a little guitar,  as well as repair, design, and build audio equipment), I would like to dig out some audio devices and create tables showing applied dB/SPL level to power output ratios for whatever I have laying around my office. Curiosity does have me wondering if lower frequencies applied to the piezo devices do indeed develop higher voltage outputs than higher frequencies. I’m also curious if I could construct a small demo of the “sound wave-guide tubing” tech I mentioned above. Also, it crosses different surfaces is converted to sound...thus on the small scale of this discussion...both the wind AND sound could conceivable be harness for power conversion.. 

Another example that comes to mind would apply if your plant/gauge is inside your home. Wind (and possibly sound) from your HVAC system could be harnessed for power sources. Ambient noises could be harness and then modified with “sound wave-guide” tech to amplify and frequency modify for optimal power conversion levels. this long-winded post ends...automobile manufacturers have been using “sound wave-guide” tech on tailpipe/muffler designs for quite some time. Depending on the desire sound...sports car with deep throaty sound versus a luxury car with almost zero sound at the muffler...are implemented simply by pipe length, bend design, and a few other variables. A world of difference a manufacturer can create utilizing the same engine in two different class/style vehicles.

  Are you sure? yes | no

samuellewis415 wrote 03/09/2021 at 22:38 point

I know multiple people have offered to buy if you sell a few. I’d also like to buy a few :) 

  Are you sure? yes | no

Tobias Friedrich wrote 03/09/2021 at 09:42 point


this project looks very interessting! It is possible to buy the hardware somewhere.

  Are you sure? yes | no

Raphael wrote 03/09/2021 at 10:20 point

Hi Tobias, thanks for the interest. Not yet, but I'm considering putting a few up for sale on tindie. I'll announce it on my twitter if that happens.

  Are you sure? yes | no

David H. Bronke wrote 03/09/2021 at 08:47 point

Do you think it would be possible to run this on an ESP8266? I have a bunch of ESP-01 modules, since they're nice and cheap. The only issue I'm seeing so far is that they might use a bit more current when active, but the deep sleep current seems the same as the ESP32.

  Are you sure? yes | no

Raphael wrote 03/09/2021 at 09:04 point

I am not super familiar with the ESP-01, but I think it should work just fine. The only requirement is to 1. Be able to generate a PWM signal; 2. Have an analog to digital converter (2 ADCs if you want to also monitor the battery)

From my quick googling, you might need to use a voltage divider to scale the analog inputs to 0-1V.

  Are you sure? yes | no

daxkamala wrote 03/08/2021 at 21:58 point

Maybe hacking a solar garden light, the cheap little push in type to protect the electronics and charge the battery?

  Are you sure? yes | no

Raphael wrote 03/09/2021 at 07:54 point

I have used a 3d printed case for some prototypes and I think they worked well (it has to be PETG instead of PLA for outside). I still need to update the stl file for the latest board layout. I'll put that up on github once it's ready.

  Are you sure? yes | no

Florian Wilhelm Dirnberger wrote 03/08/2021 at 18:42 point

How did you determine suitable PWM parameters? In your source code I can read (e.g.) 500kHz. It is that high because the (parasite) capacitance is in the pF and the resistances are in the 10k range, obviously. 

  Are you sure? yes | no

Raphael wrote 03/08/2021 at 18:55 point

Hi Florian, great question. You're right, the capacitance is in the order of 5-10pF. We need the RC circuit to charge up during a PWM high cycle, so we can play around with the resistor parameter and the PWM frequency. I think we could get it to work with a wide range of PWM frequencies, if we adjust R accordingly.

The only other attention point is the other part of the circuit that outputs the analog voltage. The _other_ RC circuit after the diode has to have a much larger time constant - it's essentially a low pass filter ( that detects the first stage's (the parasitic RC) peaks. So with these constraints I guessed a 10k resistor and ended up with a 500kHz square wave.

  Are you sure? yes | no

Florian Wilhelm Dirnberger wrote 03/09/2021 at 06:07 point

Thanks for the comprehensive answer. I wondered about that 1M resistor already. But the actual discharge of the (parasite) capacitance is thru R5 (1K, CSen+) and Q2, if I am reading your schematic correctly. I think I got it, it is kinda tricky :). 

Really nice project btw. Grüße in die Schweiz.

  Are you sure? yes | no

Raphael wrote 03/09/2021 at 07:49 point

You are correct. In the negative PWM cycle, R5 is conducting. This is the "fast discharge" part of the cycle, where I want Csen+ to be pulled fast to ground. The sensor also works without this fast discharge trick, but Csen+ keeps oscillating somwehere in the middle of Vin, and we lose some range. By quickly pulling it to the GND on the negative swing, there's more room for observing a good charging curve on the positive swing, starting from 0, instead of having Csen+ half charged already.

Freundlichen Grüßen!

  Are you sure? yes | no

John (EBo) David wrote 03/08/2021 at 05:15 point

Are these available any place?  I would love to have a couple to tests and play with.  

  Are you sure? yes | no

Raphael wrote 03/08/2021 at 18:50 point

Hi John, I'm glad you're interested. I haven't put these up for purchase anywhere yet. I've been asked a few times - maybe it's time to open up a tindie shop :)

  Are you sure? yes | no

daxkamala wrote 03/08/2021 at 21:48 point

I would buy a few for starters, I know exactly where I would use them.

  Are you sure? yes | no

Dingus wrote 03/07/2021 at 22:27 point

Does the ESP board have bluetooth? Another way of keeping power down is to just do a BLE advertising packet. It requires an additional computer to pick up the BLE packets to process upstream of the MQTT broker, but it should extend the life of the sensor. I've done just this with some cheap Xiaomai thermometers with a PiZero acting as the BLE receiver and they're giving me over 6 months on a bog standard coin cell battery.

Super interested in this as I've put IOT thermometers all over a friend's greenhouse, reporting the data back to an MQTT broker (over LoRa) and soil sensors were the next thing we were thinking about. This project looks like it would be perfect.

Edit: Just read the Github README about BLE.

  Are you sure? yes | no

Raphael wrote 03/08/2021 at 18:49 point

I completely agree that BLE is a good candidate. Yes, the ESP32 has BLE but the radio is still relatively power hungry (~100mA when transmitting, from my quick-and-dirty tests), specially when compared with purpose-built nrf chips.

My next project will likely be a nrf-based BLE version of this.

  Are you sure? yes | no

Ivan Stepaniuk wrote 03/07/2021 at 20:08 point

Very nice! Battery life seems reasonable. I see no reason for transmitting more than once a day. Is there any? Even every 48hs! If it ends up in for sale I'd definitely buy a couple.

  Are you sure? yes | no

Raphael wrote 03/08/2021 at 18:47 point

Hi Ivan, thanks for the kind words. The transmission period is just something that worked okay for my use case. Buffering a few reads and transmitting once a day is also totally reasonable.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates