Anthonyfromtheuk
Posts: 17
Joined: Sat Mar 29, 2014 3:28 pm
Location: UK

Using rain sensor?

Mon Apr 21, 2014 12:01 pm

Hello, I purchased this rain sensor from ebay
Image
http://www.ebay.co.uk/itm/Rain-Water-Se ... 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?

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Using rain sensor?

Mon Apr 21, 2014 1:04 pm

Hi,
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.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

Anthonyfromtheuk
Posts: 17
Joined: Sat Mar 29, 2014 3:28 pm
Location: UK

Re: Using rain sensor?

Mon Apr 21, 2014 3:10 pm

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.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
state = GPIO.input(23)

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

al28
Posts: 14
Joined: Sat Jan 05, 2013 7:20 pm

Re: Using rain sensor?

Tue May 13, 2014 8:37 am

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?
thanks

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Using rain sensor?

Tue May 13, 2014 9:04 am

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 :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

al28
Posts: 14
Joined: Sat Jan 05, 2013 7:20 pm

Re: Using rain sensor?

Tue May 13, 2014 9:37 am

many thanks for the reply!
ciao

pangren
Posts: 42
Joined: Thu Dec 19, 2013 2:52 pm

Re: Using rain sensor?

Tue Mar 03, 2015 9:10 am

Hi, would you be so kind as to attach a picture / schematic of how you connect it to your raspberry pi?

al28
Posts: 14
Joined: Sat Jan 05, 2013 7:20 pm

Re: Using rain sensor?

Fri Mar 06, 2015 7:15 am

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.
http://www.freedummies.com

h3ml0ck
Posts: 1
Joined: Sat Jul 04, 2015 6:00 am

Re: Using rain sensor?

Sat Jul 04, 2015 6:24 am

Hi
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.

JameDam
Posts: 2
Joined: Sat Jan 23, 2016 10:48 am
Location: Dongguan China
Contact: Website

Re: Using rain sensor?

Sat Jan 23, 2016 11:29 am

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
viewtopic.php?f=91&t=113659
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?
stay hungry stay foolish

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Using rain sensor?

Sat Jan 23, 2016 5:15 pm

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.

JameDam
Posts: 2
Joined: Sat Jan 23, 2016 10:48 am
Location: Dongguan China
Contact: Website

Re: Using rain sensor?

Mon Mar 21, 2016 7:33 am

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 botbook_mcp3002.py file

Code: Select all

# (c) BotBook.com - Karvinen, Karvinen, Valtokari

# Installing spidev:
# sudo apt-get update
# sudo apt-get -y install git python-dev
# git clone https://github.com/doceme/py-spidev.git
# cd py-spidev/
# sudo python setup.py install

import spidev # installation help in botbook_mcp3002.py comments
import time

def readAnalog(device = 0,channel = 0):
        assert device in (1, 0)
        assert channel in (1, 0)
        #open spi
        spi = spidev.SpiDev()
        spi.open(0, 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.
"botbook_mcp3002.py" 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__":
        main()
here are my reference sites
viewtopic.php?f=91&t=113659
http://www.learningaboutelectronics.com ... rry-pi.php
http://www.learningaboutelectronics.com ... rry-Pi.php
http://www.instructables.com/id/Wiring- ... /?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?
stay hungry stay foolish

grahamed
Posts: 277
Joined: Mon Jan 30, 2012 7:01 pm

Re: Using rain sensor?

Wed Mar 23, 2016 10:41 pm

Hi

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.

Return to “Automation, sensing and robotics”