Page 1 of 1

Using rain sensor?

Posted: Mon Apr 21, 2014 12:01 pm
by Anthonyfromtheuk
Hello, I purchased this rain sensor from ebay
Image ... 1e8429c3cd
And I am wanting to get it working with my rpi. when I have it powered and dip it in water the led on it lights up so it definitely works but what I don't know is how to wire it up so i can read that it has sensed water. It has a digital and analog output. can anybody assist?

Re: Using rain sensor?

Posted: Mon Apr 21, 2014 1:04 pm
Anthonyfromtheuk wrote:It has a digital and analog output
Supply the circuit with 3.3V, connect its digital output to a GPIO pin, set this pin as input and read its state in a loop. When the rain is detected, this state is low.

Best wishes, Ivan Zilic.

Re: Using rain sensor?

Posted: Mon Apr 21, 2014 3:10 pm
by Anthonyfromtheuk
Got this working, thanks for your reply

Code: Select all

#!/usr/bin/env python

from time import sleep
import os
import RPi.GPIO as GPIO

GPIO.setup(23, GPIO.IN)
state = GPIO.input(23)

if (state == 0):
    print "Water detected!"
    print "Water not detected"

Re: Using rain sensor?

Posted: Tue May 13, 2014 8:37 am
by al28
hi, I successfully connected the sensor but I would know if I need to put a resistor (4.7 or 10 kohm) like usually is done with 1-wire temperature sensor?

Re: Using rain sensor?

Posted: Tue May 13, 2014 9:04 am
by simplesi
That's a nice cheap sensor to play with :)

No need for a resistor is if supplying it via 3.3V

I'm off to ebay to get one :)


Re: Using rain sensor?

Posted: Tue May 13, 2014 9:37 am
by al28
many thanks for the reply!

Re: Using rain sensor?

Posted: Tue Mar 03, 2015 9:10 am
by pangren
Hi, would you be so kind as to attach a picture / schematic of how you connect it to your raspberry pi?

Re: Using rain sensor?

Posted: Fri Mar 06, 2015 7:15 am
by al28
hi, if you want you can look at my website where I describe how connect rain sensor to raspi. It is in italian language but if you can't google translate or you do not understand you can tell me.

Re: Using rain sensor?

Posted: Sat Jul 04, 2015 6:24 am
by h3ml0ck
i have raspberri pi2 and connect
VCC to gpio 2
GND to gpio 6
D0 to gpio23
But I have the following print :
Water detected!

I want to do with the port A0 &I wanted to be able to measure the humidity
Please, please help.

Re: Using rain sensor?

Posted: Sat Jan 23, 2016 11:29 am
by JameDam
AO analog output can be connected to the microcontroller AD port to detect the size of the drops in the above rainfall.
the above is there your eBay page, I today met the similar trouble in using the sensor MQ135, then found some solutions there viewtopic.php?f=63&t=112468
the same as the YL 83 rain sensor,MQ135 also has DOUT and AOUT, without the ADC(analog to digital converter), you only can connect the Dout with the board getting whether there is smog but can't get the value of PPM(air quality index). I guess this rain sensor also need a ADC, otherwise you only can get whether it is rain but you can not measure the size of the drops in the above rainfall, I bought a MCP3202 but the package still on the way so I can't test the YL 83 whit the ADC, anybody had read the size of rainfall successfully and has the python codes?

Re: Using rain sensor?

Posted: Sat Jan 23, 2016 5:15 pm
by stderr
About the rain drop detector, if you have a detection because a drop falls on the plate, what about the next drops? I mean, does the thing have to dry off before you can detect that another drop hits it?

This seems important to me because you might want to know if it is slightly raining now and then want to know if that is also true five minutes from now.

Re: Using rain sensor?

Posted: Mon Mar 21, 2016 7:33 am
by JameDam
I have read its analog output successfully, and just use the MCP3002
this rain sensor wiring is

YL83 vcc -> 5v
YL83 gnd -> 0v
YL83 ao -> mcp3002 CH1

mcp3002 CS -> rpi CE0
mcp3002 CH0 -> 0v or another analog
mcp3002 VSS -> 0v
mcp3002 DIN -> rpi MOSI
mcp3002 DOUT -> rpi MISO
mcp3002 CLK -> rpi SCLK
mcp3002 VDD -> 5v

and copy this code to create file

Code: Select all

# (c) - Karvinen, Karvinen, Valtokari

# Installing spidev:
# sudo apt-get update
# sudo apt-get -y install git python-dev
# git clone
# cd py-spidev/
# sudo python install

import spidev # installation help in comments
import time

def readAnalog(device = 0,channel = 0):
        assert device in (1, 0)
        assert channel in (1, 0)
        #open spi
        spi = spidev.SpiDev(), device)
        Protocol start bit (S), sql/diff (D), odd/sign (C), MSBF (M)
        Use leading zero for more stable clock cycle
        0000 000S DCM0 0000 0000 0000
        Sending 3 8bit packages so xpi.xfer2 will return the same amount.
"" 56 lines, 1743 characters
and create another file in same directory

Code: Select all

import time
import botbook_mcp3002 as mcp #

rainLevel= 0

def readRainLevel():
        global rainLevel
        rainLevel= mcp.readAnalog(0, 1 ) # the second param is which port of MCP3002 you want to read(eg: want to read CH0 set it is 0, want to read output from CH1 set 1)

def main():
        while True: #
                readRainLevel() #
                print ("Current rain level is %i " % rainLevel) #
                time.sleep(0.5) # s

if __name__=="__main__":
here are my reference sites
viewtopic.php?f=91&t=113659 ... rry-pi.php ... rry-Pi.php ... /?ALLSTEPS
and then you run second code it will print the output,
but the output is no meaning for me, anybody know the how to convert it to amount of rain?

Re: Using rain sensor?

Posted: Wed Mar 23, 2016 10:41 pm
by grahamed

I have had many of these modules. They all said they had analog output but really they didn't.

The 8-leg thing is a comparator which basically compares the resistance of the sensor with a fixed resistor (by reading the voltage of the divider formed by the sensor and the high value resistor).

The sensor resistance seems to go from near infinite to quite a low value as soon as any water gets on the sensor - it is hardly a linear measurable thing. Unless anyone knows different in which case I'd really like to hear about it.