This circuit is designed to monitor soil moisture levels using a SparkFun Soil Moisture Sensor and provide visual and auditory feedback based on the moisture level. An Arduino UNO serves as the central microcontroller unit to process the sensor data. If the soil moisture level is below a predefined threshold, the circuit activates a buzzer and lights up a red LED. Conversely, if the moisture level is above the threshold, a green LED is lit. The circuit includes resistors to limit current to the LEDs.
One end connected to the cathode of the red LED
The other end connected to the common ground net
One end connected to the cathode of the green LED
The other end connected to the common ground net
/*
* This Arduino Sketch reads the soil moisture level from a sensor connected to
* A0. If the soil moisture level is below a certain threshold, it activates a
* buzzer connected to D8 and lights up a red LED connected to D2. If the soil
* moisture level is above the threshold, it lights up a green LED connected to
* D3.
*/
const int soilMoisturePin = A0; // Soil moisture sensor signal pin
const int buzzerPin = 8; // Buzzer pin
const int redLEDPin = 2; // Red LED pin
const int greenLEDPin = 3; // Green LED pin
const int threshold = 500; // Threshold for soil moisture
void setup() {
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
pinMode(redLEDPin, OUTPUT); // Set red LED pin as output
pinMode(greenLEDPin, OUTPUT); // Set green LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int soilMoistureValue = analogRead(soilMoisturePin); // Read soil moisture
Serial.print("Soil Moisture: ");
Serial.println(soilMoistureValue); // Print soil moisture value
if (soilMoistureValue < threshold) {
digitalWrite(buzzerPin, HIGH); // Activate buzzer
digitalWrite(redLEDPin, HIGH); // Turn on red LED
digitalWrite(greenLEDPin, LOW); // Turn off green LED
} else {
digitalWrite(buzzerPin, LOW); // Deactivate buzzer
digitalWrite(redLEDPin, LOW); // Turn off red LED
digitalWrite(greenLEDPin, HIGH); // Turn on green LED
}
delay(1000); // Wait for 1 second before next reading
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the necessary pins as outputs and continuously reads the soil moisture level. Depending on the moisture level, it controls the state of the buzzer and LEDs accordingly.