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

Arduino-Controlled Automated Roof with Rain Sensor and Solar Power

Image of Arduino-Controlled Automated Roof with Rain Sensor and Solar Power

Circuit Documentation

Summary

This circuit is designed to automatically control a motorized roof based on rain detection. It utilizes two Arduino Mega 2560 microcontrollers to manage inputs and outputs, a rain sensor to detect rain, an L298N DC motor driver to control two DC motors, a 12v battery as the power source, and a solar panel with a solar charge controller to recharge the battery.

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 can control up to two DC motors with direction and speed control.

Motors

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

Power Sources

  • 12v Battery: Provides the main power supply for the motor driver and motors.
  • Solar Panel: Generates electrical power by converting solar radiation into direct current electricity.
  • Solar Charge Controller: Manages the power coming from the solar panel to charge 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: Connected to the ground of 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.
  • GRD: Connected to the ground of the Arduino Mega 2560.
  • DO: Connected to the D2 PWM pin of the Arduino Mega 2560.

L298N DC Motor Driver

  • GND: Connected to the ground of the solar charge controller and Arduino Mega 2560.
  • 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 Motor

  • Pin 1 & 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 (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 (Secondary Controller)

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

}

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

}

This secondary controller currently has no specific functionality defined in the provided code. It may be used for future expansion or additional features.