Page 1 of 1

Capacitive Rain Sensor

Posted: 15 Mar 2019, 23:50
by Shardan
The usual cheap rain sensors from AliExpress and other platforms have some disadvantages.

They work by conductance so the electrodes must have direct contact to the water.
Dirt and aging can influece this, the water conductance may differ depending on
what a raindrop collected on it's way through the air.

Worse, these sensors mostly use DC. Over time the sensor gets corroded by electrolysis.

This design uses a capacitive sensor. It is covered by solder resist, on top I sprayed a thin
urethane film for better environment resistance.
RainSensor_Cpl.jpg (382.92 KiB) Viewed 4007 times
The complete sensor fits into a box of 83x58x33mm soit's about half size compared to usual sensors.
RainSensor_Open.jpg (713.45 KiB) Viewed 4007 times
The sensor itself is built around an ATtiny 2313 CPU as it needs more speed then ESP8266 and ESPEasy can deliver.
It measures the capacitance of the sensor by measuring the loading time of the sensors capacitance.
Capacitance varies due to the dielectric constant of the isolation. The sensor board itself has a
dielectric constant of around 4, pure water is around 80 so water on the sensor makes the
capacitance bigger, it takes longer do load it. This difference is measured.

The ATTiny gives three signals for "a bit", "rainy" and "really wet".
The signals are connected to switch inputs of the ESP-07S, LEDs on the PCB show the signal states.
Internally the ATTiny uses a "Meridian" calculation to keep the measurement stable.
Threshholds can be changed in the source of ATTiny firmware.
On top there is a DS18B20 in the box. As it gets warm in the box it is not suitable to
gather environment temperature. It is used to switch the sensor heating on if temperature
gets under a certain level to avoid water freezing on the sensor or snow settling on the surface.
The sensor is heated if it gets wet or temperature is low.

If anyone wants firmware and/or PCBs message me.
(PCB's, ATTiny firmware and schematic designed by me)

Re: Capacitive Rain Sensor

Posted: 15 Mar 2019, 23:52
by grovkillen
Awesome! Let's start sell them! 8-)

Re: Capacitive Rain Sensor

Posted: 16 Mar 2019, 00:07
by Shardan
I still want to make some changes to the firmware.
It works nice, the ESP does the heating control well...
But the setting of threshhold values by recompiling and flashing firmware isn't to my likings.

It should be possible to read the values from serial and store them into the EEprom area of the chip.
The usual progger for the ESP and a terminal program should do.
The serial interface is already implemented, I use it for calibrating, it sends the actual timecounter value.
The serial receiving part still has to be done.
If ESPEasy gets a real serial for controlling some day, setting of these values should be possible
even via ESPEasy. Just read the value from the ATTiny and set threshhold values accordingly, that would be perfect.

But when setting thershholds via serial is done selling is possible I think.

Re: Capacitive Rain Sensor

Posted: 22 Jun 2019, 11:06
by SzuR
Great project can you please send me pcb's and sketch?
My email is

Re: Capacitive Rain Sensor

Posted: 22 Jun 2019, 12:00
by Shardan
SzuR wrote:
22 Jun 2019, 11:06
Great project can you please send me pcb's and sketch?
My email is
I can't send a sketch, as it is not based on the Arduino IDE.
All PCB's can be obtained from me, later maybe from Grovkillen's shop.

Re: Capacitive Rain Sensor

Posted: 02 Dec 2019, 08:33
by Maxime28
Just discover a rain sensor created with a normal rain sensor and a smart home water sensor on Not sure it would be a good model or not cause it's just a 3d printing share. :D

Re: Capacitive Rain Sensor

Posted: 02 Dec 2019, 08:38
by TD-er
It is a nice idea.
Only thing I see which strikes me as odd, is that it has the "cover" over the edge of the sensor at the bottom.
This will keep some water in it and that will break during winter.

ShardanX sent me such a sensor which is basically a PCB with solder mask covering the entire "collecting" surface of the PCB.
So far it is working just great.

Re: Capacitive Rain Sensor

Posted: 21 May 2020, 10:44
by pinelesss
Hello Shardan,
Congratulations, great project.
I would like to do a similar project to my security alarm system, using the Radiocontrolli Capacitive Rain Sensor ( ... ain-sensor).
Could you describe the heater's operating conditions in your project (launch conditions) or send me your source code?
I need to integrate the rain sensor with twilight sensor, and others.
B.R. Rafal

Re: Capacitive Rain Sensor

Posted: 22 May 2020, 10:25
by martinus
Shardan wrote:
16 Mar 2019, 00:07
I still want to make some changes to the firmware.
It works nice, the ESP does the heating control well...
But the setting of threshhold values by recompiling and flashing firmware isn't to my likings.
Nice project! Again proves that having a dedicated low-level MCU added to the architecture can be useful or even required in some cases.

I'm working on a "MiniProExtenderPlus" version for my servo prototyping solution. Thinking if an Arduino Pro Mini board would be a better fit for these kind of projects. It uses an enhanced version of the P011_PME plugin that can also read/write EEPROM values and read the VCC voltage. And store values from/to the Atmega386 RAM because the ESP is dead inbetween wake-ups.

ATTiny85 has also been one of my favourite devices in the past, but i think that a Pro Mini board is quite a lot easier for many users. Even cheaper.

Maybe having our own "ProMiniEasy" eco-system in companion with a more enhanced P011 plugin would be nice in order to get some sort of architecture standard?

It should also be possible to OTA upgrade the ATMega328 firmware using ESPEasy as a telnet/serial bridge used by AVRDude.

Re: Capacitive Rain Sensor

Posted: 22 May 2020, 12:18
by Shardan
Hello martinus,

for this type of rain sensor a separate MCU is definitely necessary.
The capacitive sensor works quite simple.
The sensor board builds a capacitor. As water has a far higher dielectric constanc then air (about 80 times..)
the capacitance rises when water drops on the sensor surface.
The MCU connects a GPIO to the sensor via a resistor.
First step: The GPIO is set to 0 volt discharging the sensor capacitance.
Then it is set to 1 loading the capacitance and a counter is started.
If a specific voltage level at the sensor is reached, a comparator stops the counter.
The counter usually gives a value around 50--60 if sensor is dry and about 250 if it is completely wet.
The rest is just calculating, building a meridian value of 15 values, setting threshholds for foggy/rainy/wet etc.

Implementing this into an ESP8266 is possible, but it is a problem with the ESPeasy framework.
Counting must run very fast so a plugin would block all other tasks while running, it needs an interrupt and
a lot of variables taking up RAM.
So I think a separate MCU is the better way for such applications.

A new MiniPro Extender would definitely be appreciated giving a lot of possibilities
the ESPeasy framework and the ESP hardware just won't allow.
It might be a good idea to give the I²C part as a lib for the Arduino IDE besides the full extender firmware.
The full version changes the Arduino mini into a GPIO extension - which is definitely nice but will
reduce the Arduino Mini to "Some more ports of ESP" again.
A given lib for connecting to a generic externder-plugin for communication with ESPEasy
gives full flexibility to use the ATmega to the limits of hardware.
So giving the Extender firmware and the lib opens up both ways, just expanding GPIOs
and free use of the MCU hardware.

Using the ATtiny 2313... well, this might be possible on smaller ATTiny chips for sure.
The ATtiny 2313 is my universal workinghorse for small applications, I've always some in my shelf.
For more complex things I use ATmega168 or 328.

Another reason for the 2313: I need some more GPIO then an ATtiny85 offers.
Meanwhile I've changed the firmware a bit. Setting the threshhold values can be done now via
the usual programmer you use for flashing the ESP8266.
Shorting a jumper starts the programming mode, then you can send the value(s) via hterm or
a similiar terminal program. The LEDs show the programming state.

One thing I would really appreciate: A generic RS232 plugin.
I've several projects meanwhile where parameters can be set via RS232 as described above...
would be nice if I could do that directly from the ESP.

At this time I'm working on a windspeed / wind direction addon for my weather station.
I've got the cheap windmill and wind vane from Ali, both around 15 EUR each...
The windmill is working nice, the vane is terrible to read and unreliable.
I'm working on a new pcb for the vane with a magnetic sensor (AS5600 from AMS).
As the windmill is chained to the vane an ATmega168 can do all measurements.
It sends data per serial... until we might have a generic RS232 it will send a "taskvalueset <speed>, taskvalueset <direction>, taskrun"...
A little trick to get values via serial, allowing much longer cabling compared to I²C.. All calculation will be done inside the wind vane.
The ATmega168 is a bit of overkill - just the smd version is very small (TQFP-32) and there's not much space inside the housing.

Re: Capacitive Rain Sensor

Posted: 22 May 2020, 19:19
by happytm

Nice project. Thank you for sharing.


I have been using PME plugin for multi channel AC dimmer since you introduced it.It opened up possibility of lot more hardware implementation as ESP lacks pins and it is cheaper than in some cases external ADCs.


Re: Capacitive Rain Sensor

Posted: 23 May 2020, 10:23
by TD-er
Shardan, I do have implemented support for the NXP SC16IS752 I2C UART bridge
So we can now have as many serial ports on an ESP as we want.

I've tried it here with 3 of these chips (6 extra ports) and it is working very stable.
It can even cope with chatty devices like GPS, which do send 9 - 11 sentences per second and sentences longer than the buffer length of the NXP chip.

Every plugin that we have that needs UART, is now also working with this bridge, so we can make a plugin for your rain sensor also, where we can exchange information in both directions.
These chips (+ crystal) are also available at JLCPCB for pick-and-place, so you can also make very cheap PCBs for it with these already mounted.