Rain Sensor Interfacing with Raspberry Pi

 1. Introduction

A rain sensor is used to detect water droplets. It works based on conductivity—when water falls on the sensor plate, it changes the electrical resistance. This sensor is commonly used in weather monitoring and automatic systems.


2. Components

  • Raspberry Pi
  • Rain Sensor Module YL-83
  • LED
  • 220Ω Resistor
  • Breadboard
  • Jumper Wires

3. Circuit and connections

Raspbery Pi
Raspberry Pi Pinout Diagram

YL-83 Rain Sensor Module Pinout Diagram
YL-83 Rain Sensor Module Pinout Diagram
Connections:

  • VCC → 5V (Pin 2)
  • GND → GND (Pin 6)
  • DO → GPIO17 (Pin 11)
  • LED + → GPIO18 (Pin 12)
  • LED – → GND (via 220Ω resistor)

4. Detailed Step By Step Circuit working

  1. Rain sensor plate detects water droplets
  2. Water reduces resistance between tracks
  3. Module converts this into digital signal
  4. DO pin changes state (LOW when rain detected)
  5. Raspberry Pi reads signal from GPIO17
  6. When rain detected → LED turns ON
  7. When dry → LED OFF

5. Libraries to be included

import RPi.GPIO as GPIO
import time

6. Code

import RPi.GPIO as GPIO
import time

rain = 17
led = 18

GPIO.setmode(GPIO.BCM)
GPIO.setup(rain, GPIO.IN)
GPIO.setup(led, GPIO.OUT)

while True:
if GPIO.input(rain) == 0: # Rain detected
GPIO.output(led, True)
print("Rain Detected")
else:
GPIO.output(led, False)
time.sleep(0.1)

7. Detailed Step By Step Code working

  1. Import GPIO and time libraries
  2. Assign rain sensor to GPIO17
  3. Assign LED to GPIO18
  4. Set GPIO mode to BCM
  5. Set rain sensor as input
  6. Set LED as output
  7. Read sensor value
  8. If LOW → rain detected → LED ON
  9. Else → LED OFF
  10. Add delay for stability

8. Tips

  • Avoid continuous water exposure (can corrode plate)
  • Clean sensor regularly
  • Adjust sensitivity using potentiometer
  • Use protective coating for long-term use

9. Uses

  • Rain detection systems
  • Automatic wiper control
  • Smart irrigation systems
  • Weather monitoring

10. Conclusion

The rain sensor is a simple and effective way to detect water presence. This project helps in building weather-based automation systems using Raspberry Pi.

തുടക്കക്കാർക്കായുള്ള ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.