This circuit is designed to automatically control a rooftop based on rain detection. It uses an Arduino Uno R3 to read input from a rain sensor and control two DC motors via an L298N motor driver. The status of the rooftop (open or closed) is displayed on a 16x2 I2C LCD. Additionally, an LED is used to indicate the status of the system.
L298N DC Motor Driver
DC Motor
12V Adapter
Arduino Uno R3
Resistor
LED: Two Pin (red)
16x2 I2C LCD
RAIN SENSOR
// 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);
}
/*
* Automatic Rooftop Sensor
* This code interfaces with a 16x2 I2C LCD to display the status of the
* rooftop (open or closed) based on the rain sensor input.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD, set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the LCD
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Rooftop Status:");
}
void loop() {
// Read the rain sensor status from the Arduino Uno
int rainDetected = digitalRead(2); // Assuming rain sensor is connected to pin D2
lcd.setCursor(0, 1);
if (rainDetected == LOW) {
lcd.print("Closing Roof ");
} else {
lcd.print("Opening Roof ");
}
delay(1000); // Update the display every second
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to