A rain detector using Arduino is a practical project aimed at detecting rainfall or moisture in the environment. It typically employs a rain sensor module that detects the presence of water droplets. Integrated with an Arduino microcontroller, the sensor continuously monitors environmental conditions. When rain is detected, the sensor sends a signal to the Arduino, which can then trigger various actions like activating warning indicators, sounding alarms, or sending alerts to connected devices. The flexibility of Arduino allows for customization and expansion of the system, enabling features such as data logging or integration with smart irrigation systems for efficient water management. This project finds applications in weather monitoring, home automation, and agriculture, offering a cost-effective solution for detecting and responding to rainfall.
Circuit Diagram :-
Note - You can Arduino uno R3 instead of R4
Code :-
// Define pin numbers
const int sensorPin = 2; // Raindrop sensor module
const int ledPin = 3; // LED
const int buzzerPin = 4; // Buzzer
void setup()
{
pinMode(sensorPin, INPUT); // Set sensorPin as input
pinMode(ledPin, OUTPUT); // Set ledPin as output
pinMode(buzzerPin, OUTPUT); // Set buzzerPin as output
Serial.begin(9600); // Start serial communication at 9600 baud rate
}
void loop()
{
int sensorState = digitalRead(sensorPin);
if(sensorState == HIGH) // Rain detected
{
digitalWrite(ledPin, LOW); // Turn LED OFF
noTone(buzzerPin); // Stop playing any tone on the buzzer
}
else // No rain detected
{
digitalWrite(ledPin, HIGH); // Turn LED ON
tone(buzzerPin, 1000); // Play a tone at 1000 Hz on the buzzer
}
Serial.println(sensorState);
delay(50);
}