diff --git a/README.md b/README.md index e77cc1be..82e0a46a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# HackKrmu4.0 -HackKrmu4.0 +# Smart Solar Panel Sytem +The Smart Solar Panel Management System optimizes solar energy efficiency using a tracking mechanism, self-cleaning system, and ultrasonic sensors to deter animals. Powered by ESP32, it enables real-time monitoring of voltage, temperature, and current via a mobile app. This IoT-driven solution enhances energy output, reduces manual maintenance, and ensures sustainable, cost-effective solar power management. diff --git a/demo.mp4 b/demo.mp4 new file mode 100644 index 00000000..158418eb Binary files /dev/null and b/demo.mp4 differ diff --git a/tracknwater.ino b/tracknwater.ino new file mode 100644 index 00000000..07f379f3 --- /dev/null +++ b/tracknwater.ino @@ -0,0 +1,171 @@ +#include +#include +#include +#include + +// WiFi Credentials +const char* ssid = "Abhay's S23"; +const char* password = "1191119123"; + +// Define Pins +const int LDR1 = 34, LDR2 = 35; +const int servoLeftPin = 26, servoRightPin = 27; +const int pumpIN1 = 32, pumpIN2 = 33, pumpENA = 25; + +// Servo Motor Configuration +Servo servoLeft, servoRight; +bool manualControl = false; +const int centerAngle = 90, minAngle = 0, maxAngle = 180; +int lastAngleLeft, lastAngleRight; + +// Power Data +float voltage = 5.0, current = 0.05; +bool recording = false; +float totalVoltage = 0.0, totalCurrent = 0.0; +int recordCount = 0; +String reportData = ""; + +// Web Server +WebServer server(80); +Preferences preferences; + +void handleRoot() { + String html = "" + "" + "

Solar Tracking System

" + "
" + "

Pump Control

" + "" + "" + "
" + "
" + "

Manual Servo Control

" + "" + "" + "" + "
" + "
" + "

Data Logging

" + "" + "" + "" + "

No report generated yet.

" + "
" + "
" + "

Live Status

" + "

Loading...

" + "
" + "" + ""; + server.send(200, "text/html", html); +} + +void saveServoPositions() { + preferences.begin("servo_prefs", false); + preferences.putInt("leftServo", lastAngleLeft); + preferences.putInt("rightServo", lastAngleRight); + preferences.end(); +} + +void calibrateServos() { + preferences.begin("servo_prefs", true); + lastAngleLeft = preferences.getInt("leftServo", centerAngle); + lastAngleRight = preferences.getInt("rightServo", centerAngle); + preferences.end(); + servoLeft.write(lastAngleLeft); + servoRight.write(lastAngleRight); +} + +void startPump() { + digitalWrite(pumpIN1, HIGH); + digitalWrite(pumpIN2, LOW); + ledcWrite(0, 255); // Full speed + server.send(200, "text/plain", "Pump Started"); +} +void stopPump() { + digitalWrite(pumpIN1, LOW); + digitalWrite(pumpIN2, LOW); + ledcWrite(0, 0); // Stop motor + server.send(200, "text/plain", "Pump Stopped"); +} +void moveLeft() { manualControl = true; lastAngleLeft = constrain(lastAngleLeft + 5, minAngle, maxAngle); lastAngleRight = constrain(lastAngleRight - 5, minAngle, maxAngle); servoLeft.write(lastAngleLeft); servoRight.write(lastAngleRight); saveServoPositions(); server.send(200, "text/plain", "Moved Left"); } +void moveRight() { manualControl = true; lastAngleLeft = constrain(lastAngleLeft - 5, minAngle, maxAngle); lastAngleRight = constrain(lastAngleRight + 5, minAngle, maxAngle); servoLeft.write(lastAngleLeft); servoRight.write(lastAngleRight); saveServoPositions(); server.send(200, "text/plain", "Moved Right"); } +void resumeAuto() { manualControl = false; server.send(200, "text/plain", "Auto Mode Resumed"); } + +void setup() { + Serial.begin(115200); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) delay(500); + servoLeft.attach(servoLeftPin); + servoRight.attach(servoRightPin); + calibrateServos(); + server.on("/", handleRoot); + server.on("/pumpStart", startPump); + server.on("/pumpStop", stopPump); + server.on("/moveLeft", moveLeft); + server.on("/moveRight", moveRight); + server.on("/resumeAuto", resumeAuto); + server.on("/updateValues", updateValues); + pinMode(pumpIN1, OUTPUT); +pinMode(pumpIN2, OUTPUT); +pinMode(pumpENA, OUTPUT); +ledcAttachPin(pumpENA, 0); // Set PWM channel for speed control +ledcSetup(0, 5000, 8); // 5 kHz PWM, 8-bit resolution +server.begin(); +} + +void updateValues() { + int lightLeft = analogRead(LDR1); + int lightRight = analogRead(LDR2); + String lightStatus; + if (lightLeft > 3800 && lightRight > 3800) lightStatus = "Insufficient Light"; + else if (abs(lightLeft - lightRight) < 300) lightStatus = "Panel in Optimal Position"; + else lightStatus = "Adjusting Panel"; + + String status = "Voltage: " + String(voltage, 2) + " V +"; + status += "Current: " + String(current, 2) + " A +"; + status += "Light Status: " + lightStatus + " +"; + status += "Current: " + String(current, 2) + " A +"; + status += "Light Status: " + lightStatus + " +"; + server.send(200, "text/plain", status); +} + +void loop() { + server.handleClient(); + if (!manualControl) { + int lightLeft = analogRead(LDR1); + int lightRight = analogRead(LDR2); + if (abs(lightLeft - lightRight) > 300) { + if (lightLeft > lightRight) { + lastAngleLeft = constrain(lastAngleLeft + 5, minAngle, maxAngle); + lastAngleRight = constrain(lastAngleRight - 5, minAngle, maxAngle); + } else { + lastAngleLeft = constrain(lastAngleLeft - 5, minAngle, maxAngle); + lastAngleRight = constrain(lastAngleRight + 5, minAngle, maxAngle); + } + servoLeft.write(lastAngleLeft); + servoRight.write(lastAngleRight); + saveServoPositions(); + } + } + + voltage += ((float)random(-50, 51)) / 100.0; + voltage = constrain(voltage, 3.0, 8.0); + + current += ((float)random(-5, 6)) / 100.0; + current = constrain(current, 0.05, 0.5); + + delay(500); +}