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

Arduino-Based Rain Detection System with Servo-Controlled Mechanism

View and Edit Project In Cirkit DesignerImage of Arduino-Based Rain Detection System with Servo-Controlled Mechanism

Circuit Documentation

Summary

This circuit is designed to control a servo motor based on the input from a rain sensor. The system uses an Arduino Uno R3 to read the rain sensor data and control the servo motor accordingly. Additionally, a 1 Channel Relay and an Adafruit MicroLipo Charger USB Type C are included in the circuit.

Component List

Servo

Arduino Uno R3

Adafruit MicroLipo Charger USB Type C

RAIN SENSOR

1 Channel Relay 5V

Wiring Details

Servo

Arduino Uno R3

Adafruit MicroLipo Charger USB Type C

RAIN SENSOR

1 Channel Relay 5V

Documented Code

Arduino Uno R3 Code

#include <Servo.h>

// Inisialisasi servo
Servo servo1;

// Inisialisasi pin sensor
const int pinHujan = 0; // Updated pin number

// Inisialisasi pembacaan sensor
int hujan;

// Inisialisasi derajat buka-tutup servo
int tutup = 150;
int buka = 10;

// ------------------------ Program Default Awal ------------------------ //

void setup() {
    // Setting baud rate serial monitor
    Serial.begin(9600);

    // Inisialisasi pin servo
    servo1.attach(4);

    // Inisialisasi status input/output pin
    pinMode(pinHujan, INPUT);
}

// -------------------------- Program Utama --------------------------- //

void loop() {
    // Pembacaan sensor
    hujan = digitalRead(pinHujan);

    // Menulis pada serial monitor pembacaan sensor hujan
    Serial.print("Hujan: ");
    Serial.println(hujan);

    // Jika kondisi hujan
    if (hujan == 0) {
        // Servo menutup
        servo1.write(tutup);
    }
    // Jika kondisi tidak hujan
    else if (hujan == 1) {
        // Servo membuka
        servo1.write(buka);
    }

    // Delay jalannya program
    delay(300);
}

Servo Code

// Memanggil library motor servo
#include <Servo.h>

// Inisialisasi servo
Servo servo1;

// Inisialisasi pin sensor
const int pinHujan = 2;

// Inisialisasi pembacaan sensor
int hujan;

// Inisialisasi derajat buka-tutup servo
int tutup = 110;
int buka = 10;

// ------------------------ Program Default Awal ------------------------ //

void setup() {
    // Setting baud rate serial monitor
    Serial.begin(9600);

    // Inisialisasi pin servo
    servo1.attach(4);

    // Inisialisasi status input/output pin
    pinMode(pinHujan, INPUT);
}

// -------------------------- Program Utama --------------------------- //

void loop() {
    // Pembacaan sensor
    hujan = digitalRead(pinHujan);

    // Menulis pada serial monitor pembacaan sensor hujan
    Serial.print("Hujan: ");
    Serial.println(hujan);

    // Sensor hujan akan bernilai = 0 saat ada air (hujan)
    // dan bernilai = 1 saat kering (tidak hujan)

    // Jika kondisi hujan
    if (hujan == 0) {
        // Servo menutup
        servo1.write(tutup);
    }
    // Jika kondisi tidak hujan
    else if (hujan == 1) {
        // Servo membuka
        servo1.write(buka);
    }

    // Delay jalannya program
    delay(300);
}

Adafruit MicroLipo Charger USB Type C Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

RAIN SENSOR Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}