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);
}
int moisture = 0;
void setup() {
// Initialize the moisture sensor power pin (use pin 2 for power)
pinMode(2, OUTPUT); // Pin to power the moisture sensor
pinMode(A1, INPUT); // Pin to read the moisture sensor value (A1)
// Initialize the LED pins
pinMode(8, OUTPUT); // LED 1
pinMode(9, OUTPUT); // LED 2
pinMode(10, OUTPUT); // LED 3
pinMode(11, OUTPUT); // LED 4
pinMode(12, OUTPUT); // LED 5
// Start serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Apply power to the soil moisture sensor (pin 2)
digitalWrite(2, HIGH);
delay(10); // Wait for 10 milliseconds for the sensor to stabilize
// Read the moisture sensor value (from A1)
moisture = analogRead(A1);
digitalWrite(2, LOW); // Turn off the sensor to avoid corrosion
// Print the moisture level to the serial monitor
Serial.println(moisture);
// Turn off all LEDs initially
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
// Determine which LED to turn on based on moisture level
if (moisture < 200) {
digitalWrite(12, HIGH); // Very dry soil (LED 5)
} else if (moisture < 400) {
digitalWrite(11, HIGH); // Dry soil (LED 4)
} else if (moisture < 600) {
digitalWrite(10, HIGH); // Moist soil (LED 3)
} else if (moisture < 800) {
digitalWrite(9, HIGH); // Wet soil (LED 2)
} else {
digitalWrite(8, HIGH); // Very wet soil (LED 1)
}
// Wait for 100 milliseconds before taking another reading
delay(100);
}
The main feedback we received from our feedback was exploring the trickle-down method in a more in-depth manner. Looking at not just having water flow after completely flooding the pot but also letting some flow out of the bottom. We also want to explore filtration systems to prevent dirt from flowing down with the water. In addition to this, we plan to see if there is time to incorporate a water sensor that will detect if the soil is dry to automatically dispense water.