The circuit is designed to monitor environmental conditions such as voltage levels and rain presence while controlling a DC motor based on sensor inputs. It includes a voltage sensing mechanism, rain detection, and an IR sensor for object detection. The circuit uses an ESP32 microcontroller to process sensor data and control a 4-channel relay module that interfaces with a DC motor. Power management is handled by a 12V battery, a step-down power converter, and a solar charge controller connected to a solar panel. The circuit also includes a voltage sensor, an IR sensor, two rain sensor modules (detection and control boards), and passive components like a resistor and an electrolytic capacitor.
12V Battery (mini):
+
to voltage sensor VCC, Relay 4 Channel 5v NO1, NO2, and step-down converter VIN+.-
to step-down converter VIN-, DC Motor pin 2, voltage sensor GND, Relay 4 Channel 5v NO3, NC3, and another 12V Battery (mini) -
.12v to 5v Step Down Power Converter:
VIN 9v-36v
not connected.VIN+
to DC Motor pin 1 and Relay 4 Channel 5v COM1.VIN-
to 12V Battery (mini) -
.USB OUTPUT 5V
not connected.5v OUTPUT
to voltage sensor vcc and Electrolytic Capacitor -
.GND
to voltage sensor gnd, Relay 4 Channel 5v GND.Solar Charge Controller:
Solar Panel:
+
to Solar Charge Controller.-
to Solar Charge Controller.Voltage Sensor DC:
signal
not connected.vcc
to step-down converter 5v OUTPUT.gnd
to step-down converter GND.GND
to 12V Battery (mini) -
.VCC
to 12V Battery (mini) +
.IR Sensor:
out
not connected.gnd
to ESP32 GND.vcc
to YL-83 Rain Sensor - Control Board VCC.YL-83 Rain Sensor - Detection Board:
POS
to YL-83 Rain Sensor - Control Board POS.NEG
to YL-83 Rain Sensor - Control Board NEG.YL-83 Rain Sensor - Control Board:
VCC
to IR Sensor vcc.GND
to ESP32 GND.DO
not connected.AO
not connected.POS
to YL-83 Rain Sensor - Detection Board POS.NEG
to YL-83 Rain Sensor - Detection Board NEG.DC Motor:
pin 1
to step-down converter VIN+.pin 2
to 12V Battery (mini) -
.Relay 4 Channel 5v:
GND
to step-down converter GND.IN1
not connected.IN2
not connected.IN3
not connected.IN4
not connected.VCC
to Resistor pin1.COM1
to step-down converter VIN+.COM2
to Solar Charge Controller.COM3
to Solar Charge Controller.COM4
not connected.NO1
to 12V Battery (mini) +
.NO2
to 12V Battery (mini) +
.NO3
to 12V Battery (mini) -
.NO4
not connected.NC1
to 12V Battery (mini) +
.NC2
to 12V Battery (mini) +
.NC3
to 12V Battery (mini) -
.NC4
not connected.GND
to IR Sensor gnd, YL-83 Rain Sensor - Control Board GND.Electrolytic Capacitor:
+
to Resistor pin2.-
to step-down converter 5v OUTPUT.Resistor:
pin1
to Relay 4 Channel 5v VCC.pin2
to Electrolytic Capacitor +
.#include <Arduino.h>
// Pin Definitions
const int voltageSensorPin = 34; // Voltage sensor analog input
const int rainSensorPin = 35; // Rain sensor analog input
const int irSensorPin = 32; // IR sensor digital input
const int relay1Pin = 26; // Relay channel 1 for DC motor
const int relay2Pin = 27; // Relay channel 2 (for future use)
const int relay3Pin = 14; // Relay channel 3 (for future use)
const int relay4Pin = 12; // Relay channel 4 (for future use)
// Voltage sensor calibration constants
const float voltageReference = 3.3; // Reference voltage of ESP32 ADC
const int resolution = 4095; // ADC resolution
const float voltageDividerRatio = 5.7; // Ratio of the voltage divider used in the sensor
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Set pin modes
pinMode(voltageSensorPin, INPUT);
pinMode(rainSensorPin, INPUT);
pinMode(irSensorPin, INPUT);
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
pinMode(relay3Pin, OUTPUT);
pinMode(relay4Pin, OUTPUT);
// Initialize relays to be off
digitalWrite(relay1Pin, LOW);
digitalWrite(relay2Pin, LOW);
digitalWrite(relay3Pin, LOW);
digitalWrite(relay4Pin, LOW);
}
void loop() {
// Voltage sensing
int voltageSensorValue = analogRead(voltageSensorPin);
float batteryVoltage = (voltageSensorValue * voltageReference / resolution) * voltageDividerRatio;
Serial.print("Battery Voltage: ");
Serial.println(batteryVoltage);
// Rain detection
int rainSensorValue = analogRead(rainSensorPin);
Serial.print("Rain Sensor Value: ");
Serial.println(rainSensorValue);
// IR sensor detection
int irSensorValue = digitalRead(irSensorPin);
Serial.print("IR Sensor State: ");
Serial.println(irSensorValue);
// Motor control based on rain and IR sensor input
if (rainSensorValue > 500) {
// If rain detected, stop the motor
digitalWrite(relay1Pin, LOW);
Serial.println("Rain detected, motor stopped.");
} else if (irSensorValue == HIGH) {
// If no rain and IR sensor detects an object, start the motor
digitalWrite(relay1Pin, HIGH);
Serial.println("IR detected, motor running.");
} else {
// If no rain and no IR detection, keep motor off
digitalWrite(relay1Pin, LOW);
Serial.println("No rain, no IR, motor stopped.");
}
// Add delays to reduce serial output spamming
delay(1000);
}
This code is designed to run on an ESP32 microcontroller. It initializes the necessary pins for reading from the voltage and rain sensors, as well as for controlling the relays connected to the DC motor. The loop function reads