working code

Jack LaRovere Abrams and Yizhe Ying

const int sensorPin = A0;

const int ledPins[4] = {2, 4, 6, 8};  // Updated LED pin numbers


void setup() {

    Serial.begin(9600);

    for (int i = 0; i < 4; i++) {

        pinMode(ledPins[i], OUTPUT);

    }

}


void loop() {

    int moisture = analogRead(sensorPin);

    Serial.print("Moisture Level: ");

    Serial.println(moisture);


    int ledCount = map(moisture, 400, 750, 0, 4);  // Adjust range based on sensor readings

    ledCount = constrain(ledCount, 0, 4);  // Ensure value stays between 0 and 4


    for (int i = 0; i < 4; i++) {

        if (i < ledCount) {

            digitalWrite(ledPins[i], HIGH);

        } else {

            digitalWrite(ledPins[i], LOW);

        }

    }


    delay(1000);

}