// ⚡ L298N Motor Driver Pins
#define IN1 5
#define IN2 4
#define ENA 3// PWM Speed Control
// 🌞 LDR Sensors (Simulating BH1750)
#define LDR_NORTH A4
#define LDR_SOUTH A5
// 🔋 Potentiometers (Simulating Voltage & Current Sensors)
#define VOLT_SENSOR A0
#define CURR_SENSOR A1
void setup() {
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
}
void loop() {
// 🌞 Read Light Sensors
int luxNorth = analogRead(LDR_NORTH);
int luxSouth = analogRead(LDR_SOUTH);
// 🔋 Read Simulated Voltage & Current
float voltage = analogRead(VOLT_SENSOR) * (5.0 / 1023.0) * 5; // Simulated 0-25V
float current = analogRead(CURR_SENSOR) * (5.0 / 1023.0) * 10; // Simulated 0-10A
float power = voltage * current;
// 🖥️ Print Readings
Serial.print("North Lux: "); Serial.print(luxNorth);
Serial.print(" | South Lux: "); Serial.print(luxSouth);
Serial.print(" | Voltage: "); Serial.print(voltage);
Serial.print("V | Current: "); Serial.print(current);
Serial.print("A | Power: "); Serial.print(power); Serial.println("W");
// ☀️ Control Motor Based on Light Difference
if (luxSouth > luxNorth + 50) {
Serial.println("Moving South...");
moveMotor("South", 150);
}
else if (luxNorth > luxSouth + 50) {
Serial.println("Moving North...");
moveMotor("North", 150);
}
else {
Serial.println("Stopping...");
stopMotor();
}
delay(2000);
}
// **Move Motor Function**
void moveMotor(String direction, int speed) {
if (direction == "South") {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
} else {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
}
analogWrite(ENA, speed);
}
// **Stop Motor Function**
void stopMotor() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0);
}