#include <Arduino.h>
#include <Wire.h>
const int RainSensorPin = A0; // Connect the rain sensor to this pin
const int Motor1Pin1 = 2; // Connect the positive terminal of motor 1 to this pin
const int Motor1Pin2 = 3; // Connect the negative terminal of motor 1 to this pin
const int Motor2Pin1 = 4; // Connect the positive terminal of motor 2 to this pin
const int Motor2Pin2 = 5; // Connect the negative terminal of motor 2 to this pin
const int RainThreshold = 500; // Set the threshold value for rain detection
const int ChargePin = A1; // Connect the solar charger output to this pin
const int BatteryPin = A2; // Connect the battery to this pin
void setup() {
pinMode(RainSensorPin, INPUT);
pinMode(Motor1Pin1, OUTPUT);
pinMode(Motor1Pin2, OUTPUT);
pinMode(Motor2Pin1, OUTPUT);
pinMode(Motor2Pin2, OUTPUT);
Serial.begin(9600);
}
void loop() {
int rainValue = analogRead(RainSensorPin);
int batteryValue = analogRead(BatteryPin);
int chargeValue = analogRead(ChargePin);
Serial.print("Rain Value: ");
Serial.println(rainValue);
Serial.print("Battery Value: ");
Serial.println(batteryValue);
Serial.print("Charge Value: ");
Serial.println(chargeValue);
if (rainValue > RainThreshold) {
// Run motor 1 in one direction
digitalWrite(Motor1Pin1, HIGH);
digitalWrite(Motor1Pin2, LOW);
// Run motor 2 in the opposite direction
digitalWrite(Motor2Pin1, LOW);
digitalWrite(Motor2Pin2, HIGH);
delay(5000); // Wait for 5 seconds
// Stop both motors
digitalWrite(Motor1Pin1, LOW);
digitalWrite(Motor1Pin2, LOW);
digitalWrite(Motor2Pin1, LOW);
digitalWrite(Motor2Pin2, LOW);
}
}