blog

A Step-by-Step Raindrop Sensor Project with Real-Time Monitoring

raindrop(1)

Have you ever encountered this problem? When you hang your clothes outside to dry, you often worry that sudden rain will wet your clothes that are almost dry. To solve this problem, we recommend the MH-RD Raindrops module rain sensor. Below, we will introduce the working principle of the MH-RD Raindrops module, connect it to Arduino to simulate rain to test its functionality, and provide a solution to this problem.

raindrop(b)

MH-RD Raindrops module

What is Raindrop module?

A raindrop sensor is a sensor used to detect the presence and intensity of rain. It usually consists of a metal plate and a sensor module. The module detects changes in the surface resistance of the metal plate to determine whether rain drops are falling, thereby achieving the perception of rainfall conditions.

What does the raindrop module consist of?

The raindrop module usually consists of two parts: the sensor board (a PCB board with parallel copper wires) and the signal comparator (built-in LM393 chip and potentiometer for adjusting sensitivity).

raindrops

How does a Raindrops sensor work?

The sensor board part of the MH-RD raindrop module is essentially a PCB board with parallel nickel-plated lines. When it is dry outside with no rain, the resistance of the parallel nickel-plated PCB board is very high, and when current is input, it is at a high voltage. When it starts to rain outside, raindrops fall on the PCB board. Since water is conductive, it will cause the parallel nickel-plated copper wires to be connected in parallel with each other, resulting in a decrease in resistance.At this time, when current is input, a low voltage is obtained.

According to the output type, raindrop sensors can be divided into analog output and digital output. The analog output can reflect the amount of rainfall, while the digital output outputs a high/low level signal when rain is detected. Based on this principle, we can connect the signal comparator part to the Arduino board, input current, and determine whether it is raining by judging whether the digital signal output by the signal comparator is high or low!

What are the advantages of MH-RD raindrops sensor?

The MH-RD raindrops sensor module has a built-in wide-voltage comparator LM393, which outputs clear and clean signals, with waveforms that are not easily distorted and strong driving ability. In addition, the PCB board part of the MH-RD raindrops sensor module adopts parallel nickel plating, which has high conductivity, long service life, and strong oxidation resistance. The module is equipped with bolt holes for easy installation.

Working Principle

Rain Drop Module Schematic Diagram(1)
Rain Drop Module Schematic Diagram(1)
Rain Drop Module Schematic Diagram(2)
Rain Drop Module Schematic Diagram(2)

Performance parameters

MH-RD Raindrops module Datasheet

We provide you with recommended data manuals for your reference.

DATASGEET

MH-RD Raindrops pinout

Raindrop pins
  • VCC: Connect to 5V voltage input
  • GND: Ground terminal
  • D0: Digital signal output pin
  • A0: Analog signal output pin
raindrop
  • VCC:Voltage input
  • GND:Ground terminal

What are the application scenarios for rain drop sensors?

Due to the detection characteristics and low cost of the raindrop sensor module, the MH-RD Raindrops module is often used in smart canopy, automotive automatic wiper systems, garden irrigation systems and other fields.

What is the difference between a rain sensor and a water sensor?

Raindrops sensor connected to Arduino

Connect the raindrop sensor module to the Arduino board, upload the code through the computer, and you can realize the detection of rain. Moreover, by adding a drive motor module, you can realize the automatic extension of the awning when it rains. Below is an example connection of the raindrop sensor module to the Arduino board, as well as a demonstration of the effect.

Sample code

We provide you with sample code.
				
					#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Define OLED screen parameters
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Create OLED object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Pin definition
const int waterLevelPin = A0;  
const int buzzerPin = 7;       
// Alarm threshold (alarm when the value is below this)
const int alarmThreshold = 300;
//  State judgment thresholds
const int highToMediumThreshold = 600;  
const int mediumToLowThreshold = 300;   
// Alarm state variable
bool isAlarming = false;
void setup() {
  // Initialize serial port
  Serial.begin(9600);
  // Configure buzzer pin as output and ensure initial state is off
  pinMode(buzzerPin, OUTPUT);
  digitalWrite(buzzerPin, LOW);  
  //  Initialize OLED
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); 
  } 
  // Initial display
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println(F("Water Level Monitor"));
  display.println(F("Ready"));
  display.display();  
  delay(2000);
}
void loop() {
    // Note: The smaller the value, the larger the raindrops/higher the water level
  int waterLevel = analogRead(waterLevelPin);  
  String waterStatus;
  if (waterLevel < mediumToLowThreshold) {
    waterStatus = "High Level";  
  } else if (waterLevel < highToMediumThreshold) {
    waterStatus = "Medium Level";  
  } else {
    waterStatus = "Low Level";  
  }  
  //  Trigger alarm only when water level is high (value below threshold) and not in alarm state 
  if (waterLevel < alarmThreshold && !isAlarming) {
    triggerAlarm();
  }  
  //  Serial port output information
  Serial.print("Water Level: ");
  Serial.print(waterLevel);
  Serial.print(" - ");
  Serial.println(waterStatus);  
  // OLED display information
  display.clearDisplay();  
  // Title
  display.setTextSize(2);
  display.setCursor(0, 0);
  display.println(F("Water"));
  // Display water level state
  display.setTextSize(1);
  display.setCursor(0, 20);
  display.print(F("Status: "));
  display.println(waterStatus);
  // Display original value
  display.setCursor(0, 35);
  display.print(F("Value: "));
  display.print(waterLevel);
  //  Display voltage value
  float voltage = waterLevel * (5.0 / 1023.0);
  display.setCursor(0, 50);
  display.print(F("Voltage: "));
  display.print(voltage, 2);
  display.print(F("V"));
  // Alarm prompt
  if (isAlarming) {
    display.setCursor(80, 50);
    display.print(F("ALARM!"));
  }
  display.display();
  delay(500);
}
// Alarm function
void triggerAlarm() {
  isAlarming = true;
  unsigned long alarmStartTime = millis();
  // Alarm continuously for 2 seconds
  while (millis() - alarmStartTime < 2000) {
    // Buzzer sounds intermittently
    digitalWrite(buzzerPin, HIGH);
    delay(500);
    digitalWrite(buzzerPin, LOW);
    delay(500);
    
    loop(); 
  }
  digitalWrite(buzzerPin, LOW);
  isAlarming = false;
}
				
			

FAQS

Why is my initial water level 1023 instead of 0?

The core of the raindrop sensor is a conductive sensing plate. When there are no raindrops, the resistance between the sensing plates is very large, close to an open circuit state, and the analog output (AO) will be close to the power supply voltage (5V). The analog input range of Arduino is 0~1023 (corresponding to 0~5V), so the reading will be close to 1023 when there are no raindrops. When there are raindrops, the raindrops act as conductors, which will reduce the resistance between the sensing plates, the analog output voltage will drop, and the reading will approach 0 from 1023, which conforms to the “low-level effective” property – the smaller the value, the higher the water level.

How to tell if a rain sensor is working?

To monitor whether the raindrop sensor is working, we can find a garden with an intelligent irrigation system, pour water on the detection plate of the sensor, and see if the sprinkler stops working. If the sprinkler stops working, it means the raindrop sensor is working normally; otherwise, it means the raindrop sensor is not working.

Do rain sensors need calibration?

Yes, raindrop sensors often need to be calibrated before use, which can improve the accuracy of raindrop measurement.

What is the difference between wired and wireless rain sensors?

Finally, we recommend B. J. Thomas’sRaindrops Keep Falling on My Head“. We hope you have a good mood every day!!!

Leave a Reply

Your email address will not be published. Required fields are marked *