This circuit is designed to automatically control an umbrella using a rain sensor and a manual switch. The core of the circuit is an Arduino UNO microcontroller, which processes the input from the rain sensor and the manual switch to control a DC motor through an L298N motor driver. The motor is responsible for opening and closing the umbrella. The system is powered by a 12V 7Ah battery, and a rocker switch is included to manually control the motor.
// Pin Definitions
const int rainSensorPin = 0; // Rain sensor connected to A0
const int motorControlPin1 = 2; // Motor control pin 1 (IN1)
const int motorControlPin2 = 3; // Motor control pin 2 (IN2)
const int manualButtonPin = 4; // Manual button pin
void setup() {
// Initialize Serial Monitor
Serial.begin(9600);
// Set motor control pins as OUTPUT
pinMode(motorControlPin1, OUTPUT);
pinMode(motorControlPin2, OUTPUT);
// Set manual button pin as INPUT
pinMode(manualButtonPin, INPUT_PULLUP); // Use internal pull-up resistor
}
void loop() {
// Read the rain sensor value
int rainValue = analogRead(rainSensorPin);
Serial.println(rainValue); // Debugging - prints rain sensor value
// Check if rain is detected (Adjust the threshold as needed)
if (rainValue < 500) { // Assuming value < 500 indicates rain
openUmbrella();
}
// Check if the manual button is pressed
if (digitalRead(manualButtonPin) == LOW) { // Button pressed
openUmbrella();
delay(3000); // Keep the umbrella open for 3 seconds
closeUmbrella();
}
delay(100); // Small delay to prevent rapid cycling
}
// Function to open the umbrella
void openUmbrella() {
digitalWrite(motorControlPin1, HIGH); // Rotate motor in one direction
digitalWrite(motorControlPin2, LOW);
Serial.println("Umbrella Opening...");
}
// Function to close the umbrella
void closeUmbrella() {
digitalWrite(motorControlPin1, LOW); // Rotate motor in the opposite direction
digitalWrite(motorControlPin2, HIGH);
Serial.println("Umbrella Closing...");
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the necessary pins, reads the rain sensor, and controls the motor based on the sensor input and manual switch state. The openUmbrella
and closeUmbrella
functions are used to control the motor's direction, simulating the opening and closing of an umbrella.