Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled Rain Alert System with Servo and Buzzer

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Rain Alert System with Servo and Buzzer

Circuit Documentation

Summary

This circuit is designed to monitor rainfall using a rain sensor and respond accordingly by actuating a servomotor and activating a buzzer. The core of the circuit is an Arduino UNO microcontroller, which reads the analog output from the rain sensor to detect the presence of rain. Upon detection, the Arduino drives a servomotor to a specified position and sounds a buzzer to alert the user. The servomotor returns to its original position when no rain is detected.

Component List

RAIN SENSOR

Servomotor SG90

Buzzer

Arduino UNO

Wiring Details

RAIN SENSOR

Servomotor SG90

Buzzer

Documented Code

#include <Servo.h>

// Define the pin for the rain sensor
const int rainSensorPin = A1; // You can change this pin as per your wiring

// Define the pin for the servo motor
const int servoPin = 8; // You can change this pin as per your wiring

// Define the pin for the buzzer
const int buzzerPin = 4;

Servo myServo;

// Function to slowly rotate the servo to a target angle
void slowRotate(int targetAngle) {
  int currentAngle = myServo.read(); // Read the current angle of the servo

  // Determine the step direction
  int step = (targetAngle > currentAngle) ? 1 : -1;

  // Rotate the servo to the target angle in small steps
  while (currentAngle != targetAngle) {
    currentAngle += step; // Increment or decrement the angle
    myServo.write(currentAngle); // Set the servo to the new angle
    delay(15); // Adjust this delay for speed; smaller = faster
  }
}

void setup() {
  // Set up the rain sensor pin as an input
  pinMode(rainSensorPin, INPUT);
  
  // Set up the buzzer pin as an output
  pinMode(buzzerPin, OUTPUT);
  
  // Set up the servo motor
  myServo.attach(servoPin);
}

void loop() {
  // Read the state of the rain sensor
  int rainState = digitalRead(rainSensorPin);
  
  // If the rain sensor detects rain (LOW), rotate the servo motor to 180 degrees
  if (rainState == LOW) {
    digitalWrite(buzzerPin, HIGH); // Turn on the buzzer before moving
    slowRotate(180); // Slowly rotate to 180 degrees
    digitalWrite(buzzerPin, LOW); // Turn off the buzzer after reaching 180 degrees
  } else {
    // If no rain is detected, rotate the servo motor to 0 degrees
    slowRotate(0); // Slowly rotate back to 0 degrees
  }
  
  // Add a small delay for stability
  delay(100);
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the rain sensor, servomotor, and buzzer, and contains the main logic for detecting rain and actuating the servo and buzzer accordingly. The slowRotate function is used to move the servo to the desired angle in small increments, providing a smoother motion.