ESP32-Based Rain-Responsive Motor Control System with Voltage Monitoring
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor environmental conditions such as voltage levels, rain presence, and object detection using an IR sensor. It includes a power management system that steps down voltage from a 12V battery to 5V, a set of sensors for voltage and rain detection, an ESP32 microcontroller for processing sensor data, and a relay module to control a DC motor based on sensor inputs. The system is also capable of being powered by a solar panel through a solar charge controller.
Component List
Power Components
- 12V Battery (mini): Provides the primary power source for the circuit.
- Solar Panel: Alternative power source that charges the battery via the solar charge controller.
- Solar Charge Controller: Manages the charging of the battery from the solar panel.
- 12v to 5v Step Down Power Converter: Converts the 12V input to a stable 5V output for components requiring 5V.
Sensors
- Voltage Sensor DC: Measures the voltage level of the battery.
- YL-83 Rain Sensor - Detection Board: Detects the presence of rain.
- YL-83 Rain Sensor - Control Board: Processes the signal from the rain detection board.
- IR Sensor: Detects the presence of objects using infrared light.
Actuators
- DC Motor: Actuator that can be turned on or off based on sensor inputs.
- Relay 4 Channel 5v: Controls the power to the DC motor and other components if needed.
Microcontroller
- ESP32 38 PINS: Processes sensor inputs and controls the relay module accordingly.
Passive Components
- Electrolytic Capacitor: Stabilizes the 5V output from the power converter.
- Resistor: Limits current or divides voltage as required in the circuit.
Wiring Details
Power Components
12V Battery (mini):
+to voltage sensor VCC, Relay NO1, NO2, and Step Down Converter VIN+.-to Step Down Converter VIN-, voltage sensor GND, Relay NO3, NC3, and DC Motor pin 2.
Solar Panel:
+to Solar Charge Controller.-to Solar Charge Controller.
Solar Charge Controller: Wired to the solar panel and other components as needed.
12v to 5v Step Down Power Converter:
VIN 9v-36vto 12V Battery +.VIN+to Relay COM1 and DC Motor pin 1.VIN-to 12V Battery -.USB OUTPUT 5VNot used in this configuration.5v OUTPUTto Electrolytic Capacitor -.GNDto voltage sensor gnd, Relay GND.
Sensors
Voltage Sensor DC:
signalNot connected in this configuration.vccto Step Down Converter 5v OUTPUT.gndto Step Down Converter GND.GNDto 12V Battery -.VCCto 12V Battery +.
YL-83 Rain Sensor - Detection Board:
POSto YL-83 Rain Sensor - Control Board POS.NEGto YL-83 Rain Sensor - Control Board NEG.
YL-83 Rain Sensor - Control Board:
VCCto ESP32 GND.GNDto ESP32 GND.DONot connected in this configuration.AONot connected in this configuration.POSto YL-83 Rain Sensor - Detection Board POS.NEGto YL-83 Rain Sensor - Detection Board NEG.
IR Sensor:
outNot connected in this configuration.gndto ESP32 GND.vccto ESP32 GND.
Actuators
DC Motor:
pin 1to Relay COM1.pin 2to 12V Battery -.
Relay 4 Channel 5v:
GNDto Step Down Converter GND.IN1Not connected in this configuration.IN2Not connected in this configuration.IN3Not connected in this configuration.IN4Not connected in this configuration.VCCto Resistor pin1.COM1to Step Down Converter VIN+ and DC Motor pin 1.COM2to Solar Charge Controller.COM3to Solar Charge Controller.COM4Not used in this configuration.NO1to 12V Battery +.NO2to 12V Battery +.NO3to 12V Battery -.NO4Not used in this configuration.NC1to 12V Battery +.NC2to 12V Battery +.NC3to 12V Battery -.NC4Not used in this configuration.
Microcontroller
- ESP32 38 PINS:
GNDto IR Sensor gnd, YL-83 Rain Sensor - Control Board GND.G23Not connected in this configuration.G22Not connected in this configuration.TXDNot connected in this configuration.RXDNot connected in this configuration.G21Not connected in this configuration.G19Not connected in this configuration.G18Not connected in this configuration.G5Not connected in this configuration.G17Not connected in this configuration.G16Not connected in this configuration.G4Not connected in this configuration.G0Not connected in this configuration.G2Not connected in this configuration.G15Not connected in this configuration.SDINot connected in this configuration.SD0Not connected in this configuration.CLKNot connected in this configuration.3V3Not connected in this configuration.ENNot connected in this configuration.SPNot connected in this configuration.SNNot connected in this configuration.G34to Voltage Sensor signal.G35to Rain Sensor AO.G32to IR Sensor out.33Not connected in this configuration.G25Not connected in this configuration.G26to Relay IN1.G27to Relay IN2.G14to Relay IN3.G12to Relay IN4.G13Not connected in this configuration.SD2Not connected in this configuration.SD3Not connected in this configuration.5VNot connected in this configuration.
Passive Components
Electrolytic Capacitor:
-to Step Down Converter 5v OUTPUT.+to Resistor pin2.
Resistor:
pin1to Relay VCC.pin2to Electrolytic Capacitor +.
Documented Code
#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 = (