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

Arduino-Controlled Automated Roof with Rain Sensor and Solar Charging

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Automated Roof with Rain Sensor and Solar Charging

Circuit Documentation

Summary

This circuit is designed to automatically control a roof based on rain detection, utilizing two Arduino Mega 2560 microcontrollers, a rain sensor, an L298N DC motor driver, two DC motors, a 12V battery, a solar panel, and a solar charge controller. The system operates by detecting rain using the rain sensor and then activating the motors through the motor driver to either open or close the roof accordingly.

Component List

Microcontrollers

Sensors

Motor Drivers

Motors

Power Sources

Controllers

Wiring Details

Arduino Mega 2560

Rain Sensor

L298N DC Motor Driver

DC Motors

12V Battery

Solar Panel

Documented Code

Arduino Mega 2560 Code (Primary Controller)

// Define pins
const int rainSensorPin = 2;  // Digital pin connected to rain sensor
const int motorPin1 = 9;      // Motor driver input pin 1
const int motorPin2 = 10;     // Motor driver input pin 2

// Define states
bool isRoofClosed = false;

void setup() {
  // Initialize pins
  pinMode(rainSensorPin, INPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);

  // Start with the roof open
  openRoof();

  Serial.begin(9600);  // Initialize serial communication for debugging
}

void loop() {
  int rainDetected = digitalRead(rainSensorPin);

  if (rainDetected == LOW && !isRoofClosed) {
    // Rain detected, close the roof
    closeRoof();
  } else if (rainDetected == HIGH && isRoofClosed) {
    // No rain, open the roof
    openRoof();
  }

  delay(1000);  // Check every second
}

void closeRoof() {
  Serial.println("Closing Roof...");
  // Rotate motor to close the roof
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);

  // Assuming it takes 5 seconds to close the roof
  delay(5000);

  // Stop the motor
  stopMotor();

  isRoofClosed = true;
}

void openRoof() {
  Serial.println("Opening Roof...");
  // Rotate motor to open the roof
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);

  // Assuming it takes 5 seconds to open the roof
  delay(5000);

  // Stop the motor
  stopMotor();

  isRoofClosed = false;
}

void stopMotor() {
  // Stop the motor by setting both inputs to LOW
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
}

Arduino Mega 2560 Code (Secondary Controller)

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

}

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

}

This secondary Arduino Mega 2560 does not have any specific functionality defined in the provided code. It appears to be a placeholder for future expansion or redundancy.