Mabaelst
(Bart Teuwen)
May 16, 2025, 11:27am
1
Hello everyone,
I have this rain sensor
And want to connect this to an esp32, so this
I have been searching on the internet but I can’t find this combination.
Can someone tell me how to connect this correctly and what code I need.
I am completely new to esp home, so I don’t understand much of the numbers on the esp32 and what they are for.
Thanks for all the info!
zoogara
(Daryl)
May 16, 2025, 11:39am
2
These have 2 outputs - a digital output (D0) that goes high when water is detected and an analog output (A0) that varies with the amount of moisture.
You can use both at the same time.
Learn how a rain sensor works, how to connect the rain sensor to ESP32, how to program ESP32 to detect the rain. The detail instruction, code, wiring diagram, video tutorial, line-by-line code explanation are provided to help you quickly get started...
Set up a GPIO binary sensor for the D0 pin:
and an ADC sensor for the A0 pin:
Mabaelst
(Bart Teuwen)
May 16, 2025, 12:05pm
3
Thank you very much for your reply. but my esp32 is not the same as used in the explanation. I am really new to esp so I dont really understand where to connect the wiring to my esp!
Karosm
(Karosm)
May 16, 2025, 5:49pm
4
It’s technically same, you can follow the tutorial.
GND to GND
VCC to D19
DO to D21
AO to VP (D36)
Mabaelst
(Bart Teuwen)
May 17, 2025, 1:29pm
5
Thank you very much for your reply.
I think it worked,
but I don’t see the rain sensor in HA.
What am I doing wrong again?
Karosm
(Karosm)
May 17, 2025, 2:32pm
6
You need to setup Esphome and when done use one of those sensor components (or both) linked above.
Mabaelst
(Bart Teuwen)
May 17, 2025, 4:08pm
7
Thanks for your reply.
If I understand correctly I need to install Esp32 in ESPHome first, then follow this tutorial?
Karosm
(Karosm)
May 17, 2025, 4:41pm
8
Exactly.
That tutorial was just for wiring and testing. You don’t run arduino code on esphome. When you have the base configuration on esphome done, you add the sensor component(s) from above.
Mabaelst
(Bart Teuwen)
May 18, 2025, 10:51am
9
Thanks for your response.
I now have the following setup
and the following configuration.
esphome:
name: terras-regensensor
friendly_name: Terras Regensensor
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "xxxxxxxxx"
ota:
- platform: esphome
password: "xxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Terras-Regensensor"
password: "xxxxxxxx"
captive_portal:
web_server:
port: 80
# Example configuration entry
sensor:
- platform: adc
pin: GPIO36
name: “Waterleak”
update_interval: 2s
and this is the result
But I really can’t get any further. What am I missing here?
Thanks for your response
Karosm
(Karosm)
May 18, 2025, 11:12am
10
Nice!
Add this to your ADC sensor
attenuation: 12dB
samples: 10
Then make a switch to power your sensor:
switch:
- platform: gpio
id: power
name: "Sensor Power"
pin: GPIO19
Later you can automate the powering and sensor reading.
Mabaelst
(Bart Teuwen)
May 18, 2025, 12:18pm
11
Thanks for thinking along.
But could you explain to me what we have actually done (as I said I am very new to ESPHome) and how can I now measure rain and the amount of rain?
Karosm
(Karosm)
May 18, 2025, 12:24pm
12
I will, when you confirm that the sensor works when powered with the switch component and you post what values you receive.
?
Mabaelst
(Bart Teuwen)
May 18, 2025, 12:28pm
13
yes the sensor turns on and off when I press the button!
But could you explain to me what we have actually done (as I said I am very new to ESPHome) and how can I now measure rain and the amount of rain?
Mabaelst
(Bart Teuwen)
May 18, 2025, 12:29pm
14
And now it looks like this.
Karosm
(Karosm)
May 18, 2025, 12:30pm
15
Turn power on and play with water…
Mabaelst
(Bart Teuwen)
May 18, 2025, 12:32pm
16
when I put water on the sensor the second led turns on
Karosm
(Karosm)
May 18, 2025, 12:34pm
17
Amount of rain no-how with that sensor.
That’s the digital output threshold.
But what readings you get on your esphome sensor?
Mabaelst
(Bart Teuwen)
May 18, 2025, 12:37pm
18
Would you be so kind to explain this a little bit so I can understand it a little better.
Karosm
(Karosm)
May 18, 2025, 12:49pm
19
Analog output voltage changes according to the presence of water on the sensor. Might be close to zero when dry and few volts when fully wet.
At best you can use that to detect when it starts raining and maybe for frost detection. But it can’t measure rain quantity.
Here in this case we power the sensor from Esp GPIO pin, something that usually has to be avoided with most sensors. Reason for this is that the sensor electrodes oxidize very quickly if powered continuously. So if you want to continue with that setup, you need to automate the sensor readings and power on cycles.
Mabaelst
(Bart Teuwen)
May 18, 2025, 12:58pm
20
So if I understand correctly I now need to create an automation that turns on the sensor switch every so often and then compares the “waterleak” value with the value when the switch is off?