Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Automated Roof with Rain Sensor and Solar Charging

Image 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

  • Arduino Mega 2560: A microcontroller board based on the ATmega2560, with numerous digital and analog I/O pins.

Sensors

  • Rain Sensor: A device that detects rainwater and provides digital or analog signals.

Motor Drivers

  • L298N DC Motor Driver: A module that allows control of two DC motors or one stepper motor.

Motors

  • DC Motor: An electric motor that runs on direct current electricity.

Power Sources

  • 12V Battery: A battery that provides a 12V power supply.
  • Solar Panel: A panel that converts solar energy into electrical energy.

Controllers

  • Solar Charge Controller: A device that regulates the voltage and current coming from the solar panels going to the battery.

Wiring Details

Arduino Mega 2560

  • 5V: Connected to the 5V power supply of the rain sensor and the other Arduino Mega 2560.
  • GND: Common ground with the rain sensor, L298N motor driver, and solar charge controller.
  • VIN: Connected to the 5V output of the L298N motor driver.
  • D2 PWM: Connected to the digital output (DO) of the rain sensor.
  • D9 PWM: Connected to the IN1 input of the L298N motor driver.
  • D10 PWM: Connected to the IN2 input of the L298N motor driver.

Rain Sensor

  • VCC: Connected to the 5V power supply of the Arduino Mega 2560.
  • GND: Connected to the common ground.
  • DO: Connected to the D2 PWM pin of the Arduino Mega 2560.

L298N DC Motor Driver

  • GND: Common ground with the Arduino Mega 2560 and solar charge controller.
  • 5V: Connected to the VIN pin of the Arduino Mega 2560.
  • IN1: Connected to the D9 PWM pin of the Arduino Mega 2560.
  • IN2: Connected to the D10 PWM pin of the Arduino Mega 2560.
  • OUT1: Connected to pin 2 of one DC motor.
  • OUT2: Connected to pin 1 of the same DC motor.
  • OUT3: Connected to pin 1 of the other DC motor.
  • OUT4: Connected to pin 2 of the other DC motor.
  • 12V: Connected to the solar charge controller.

DC Motors

  • Pin 1 and Pin 2: Connected to the OUT1 and OUT2 (or OUT3 and OUT4) of the L298N motor driver.

12V Battery

  • +: Connected to the solar charge controller.
  • -: Connected to the solar charge controller.

Solar Panel

  • VCC: Connected to the solar charge controller.
  • GND: Connected to the solar charge controller.

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.