// Define the pins for the potentiometers and LDRs
const int potentiometerPins[] = {A4, A5, A6, A7};
const int ldrPins[] = {A0, A1, A2, A3};
const int numSensors = 4;
unsigned long previousMillis = 0;
const long interval = 500; // 1 second interval
void setup() {
// Start serial communication
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
// Check if it's time to read and display values
if (currentMillis - previousMillis >= interval) {
// Save the last time you read the values
previousMillis = currentMillis;
for (int i = 0; i < numSensors; i++) {
// Map the potentiometer value to a range of 1 to 200
int x = map(analogRead(potentiometerPins[i]), 0, 1023, 100, 20000);
float xfloat = x/100.00;
// Read the value of the LDR and map it
int y = map(analogRead(ldrPins[i]), 8, 1015, 10000, 1);
// Calculate the adjusted LDR value as a percentage
float FinalVal = ((float)xfloat * (float)y) / 100.00;
// Print the values to the serial monitor
Serial.print("Sensor: ");
Serial.print(i + 1);
Serial.print("\t Sensitivity: ");
Serial.print(xfloat);
Serial.print("\t ldr: ");
Serial.print(y);
Serial.print("\t FinalVal: ");
Serial.println(FinalVal);
}
}
}