// Pin connections
const int motorPin1 = 2; // Control pin 1 of the L293D motor driver (IN1)
const int motorPin2 = 3; // Control pin 2 of the L293D motor driver (IN2)
const int motorPin3 = 4; // Control pin 3 of the L293D motor driver (IN3)
const int motorPin4 = 5; // Control pin 4 of the L293D motor driver (IN4)
const int lightSensorPin = A0; // Analog input pin for the light sensor
// Constants
const int threshold = 500; // Light intensity threshold for triggering movement
// Variables
int lightIntensity = 0; // Variable to store the light intensity reading
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(lightSensorPin, INPUT);
}
void loop() {
lightIntensity = analogRead(lightSensorPin); // Read the light intensity
if (lightIntensity > threshold) {
// Move the solar panel in one direction
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
} else {
// Move the solar panel in the opposite direction
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
}
}